Cyclic imports

James at
Fri Jun 27 05:40:42 CEST 2008

Hi all,
I'm looking for some advice dealing with cyclic, cross-package

I've created the following demo file structure:
./ imports a class from and vice versa, and imports
them both.

However, because has not been completely read by the time it gets
to the:
from b import b
line, the
from a import a
line in fails with an import error (stack trace at the end).

I hope that's clear: basically, because of the cyclic import, I see
incomplete modules which can't be imported.

Can I have this module hierarchy in some other way?


Stack trace from example:
  File "", line 1, in <module>
    from a import a
  File "/Users/james/tmp/python/a/", line 1, in <module>
    from b import b
  File "/Users/james/tmp/python/b/", line 1, in <module>
    from a import a
ImportError: cannot import name a

More information about the Python-list mailing list