Reputation: 5188
Suppose I need the function foo
and that foo
just so happens to be defined under library.lgmodule.medmodule.smmodule.nichemodule.utils.something.else
Is there a cleaner way to write:
from library.lgmodule.medmodule.smmodule.nichemodule.utils.something.else import foo
e.g. akin to the multi-line import
:
from module.utiles import (foo, bar, baz, ban, ana,
some, more, funcs, etc)
Upvotes: 0
Views: 190
Reputation: 2046
You could use importlib.import_module
and use some kind of string formatting.
For example:
from importlib import import_module
path = '.'join[
'library',
'lgmodule',
'medmodule',
'smmodule',
'nichemodule',
'utils',
'something',
'else'
]
foo = import_module('{}.foo'.format(path)
Upvotes: 1