import question
Josiah Carlson
jcarlson at uci.edu
Mon Apr 5 18:33:47 EDT 2004
> So, how to avoid this? How can I refer back to a module higher in the "hierarchical" path.
> Up is so easy.. just say import foo.foo2.foo3. But up, what is the correct way of doing that?
> Something to put in __init__.py, like sys.path.apppend('..')? Looks ugly to me....
PEP 328, Relative imports should take care of your issue.
In the meantime...
#in main.py
import lib
#in foo1.py and foo2.py
import sys
lib = sys.modules['lib']
Now both of them will refer to the same 'lib' that main.py imported.
- Josiah
More information about the Python-list
mailing list