Relative Imports, why the hell is it so hard?

CinnamonDonkey CinnamonDonkey at googlemail.com
Mon Mar 23 10:16:30 EDT 2009


Hi All,

I'm fairly new to Python so I still have a lot to learn. But I'd like
to know how to correectly use relative imports.

Please, please... please! don't go off on rants about why you think
relative imports should not be used. I've got 15+ years in C++ and
relative inclusion of other sections of code has never been a problem.
As far as I am concerned what I am trying to do is perfectly
reasonable and valid.

Thank you in advance to everyone who helps solve this, because I just
don't get it.

Example:

\ App
|   main.py
+--\subpack1
|   |   __init__.py
|   |   module1.py
|
+--\subpack2
|   |   __init__.py
|   |   module2.py


Module1 needs to access functionality in Module2.

#module1.py
from ..subpack2 import module2

Seems reasonable to me... but it just does not work and I was so
liking Python. :(



More information about the Python-list mailing list