问题
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