如何从给定绝对路径的模块导入函数? [英] How to import function from a module given absolute path?

查看:244
本文介绍了如何从给定绝对路径的模块导入函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from bar import foo 

允许导入函数foo来自模块栏,没有导入整个模块。

allows one to import function foo from module bar, without importing the whole module.

现在,这个帖子: Python 3.4:如何在给定完整路径的情况下导入模块?显示不同的根据python的版本,在给定模块的完整路径的情况下导入模块的方法。

Now, this thread: Python 3.4: How to import a module given the full path? shows different methods to import a module given it's full path depending on python's version.

它们是一种从模块栏导入函数foo的方法,给定了bar的绝对路径而没有导入整个模块栏?

Is their a way to import function foo from module bar given the absolute path of bar and without importing whole module bar ?

提前感谢任何提示

推荐答案

否,没有这样的方式。

那说......

from bar import foo 

还导入整个模块 bar

它就像:

import bar
foo = bar.foo
del globals['bar']

这篇关于如何从给定绝对路径的模块导入函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆