1
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

Community
  • 1
  • 1
Trolldejo
  • 466
  • 1
  • 7
  • 20
  • I don't think there's `import x from y` syntax in Python, what you're probably looking for is `from x import y`. And no, it doesn't allow the said behavior, it still runs through the whole module. The only difference is that you don't get the module namespace. – Markus Meskanen May 18 '17 at 12:34
  • thanks for your comment, I did edit my answer accordingly. – Trolldejo May 18 '17 at 12:47

1 Answers1

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']
Yoav Glazner
  • 7,936
  • 1
  • 19
  • 36