Relative Imports, why the hell is it so hard?

skip at skip at
Mon Mar 23 15:44:03 CET 2009

    >> 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.

However, C++ != Python.  Regardless whether or not you can "make it work",
translating idioms from one language to another is often suboptimal.  That
may not be the case here, but it bears keeping in mind.

    >> Example:

    >> \ App
    >> |
    >> +--\subpack1
    >> |   |
    >> |   |
    >> |
    >> +--\subpack2
    >> |   |
    >> |   |

    >> Module1 needs to access functionality in Module2.

    >> from ..subpack2 import module2

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

You might try removing a dot from your import statement.  Python is also not
Unix.  Popping up one level in the package hierarchy is done with ".", not

Skip Montanaro - skip at -

More information about the Python-list mailing list