How to use a common script for all import systems?
By the way, I agree that import * not the biggest idea. This makes sense when using the importer , but I'm not sure about your overall setup. In addition, you need to be careful about circular imports.
So, my answer is specifically intended only so that I need to write the same code import modules :, and not regarding the meaning of your installation as a whole.
Proof of concept, importer is what you really need .:
βββ pack β βββ __init__.py β βββ importer.py β βββ mgmt_1.py β βββ mgmt_2.py βββ test.py
test.py
import pack pack.foo_1() pack.foo_2()
init.py from mgmt_1 import * from import mgmt_2 *
mgmt_1.py
from .importer import * print "sys", sys print "os", os def foo_1(): print "foo_1"
mgmt_2.py:
from .importer import * print "sys", sys print "os", os def foo_2(): print "foo_2", dir(sys)[0:5]
importer.py
import sys import os
exit:
sys <module 'sys' (built-in)> os <module 'os' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc'> sys <module 'sys' (built-in)> os <module 'os' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc'> foo_1 foo_2:sys ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__']
source share