如何从给定绝对路径的模块导入函数?
问题描述:
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']