How to import function from a module given absolute path?

ε祈祈猫儿з 提交于 2019-12-24 09:49:59

问题


from bar import foo 

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

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.

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

Thanks in advance for any tips


回答1:


No, there is no such way.

That said...

from bar import foo 

Is also importing the whole module bar

it is like:

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


来源:https://stackoverflow.com/questions/44046615/how-to-import-function-from-a-module-given-absolute-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!