Coping with cyclic imports

Torsten Bronger bronger at physik.rwth-aachen.de
Tue Apr 8 16:06:46 EDT 2008


Hallöchen!

I have a rather fat module that represents a document parser --
inline elements, block elements, and the like.  Now I want to split
it into many modules to make everything more manageable.

But at the moment I don't see how to avoid cyclic imports:  A
document element A, which is represented my module parser.A, may
contain the element B, as defined in parser.B.  And vice versa.  So
both modules must import each other, as far as I can see.

I know that cyclic imports work in Python under certain
circumstances.  Can anyone refer me to a page which explains *when*
this works?  Because at least once, the imported module was not
"finished" and thus largely unusual.

Thank you!

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                                      Jabber ID: bronger at jabber.org
               (See http://ime.webhop.org for further contact info.)



More information about the Python-list mailing list