Cyclic imports

James rent.lupin.road at gmail.com
Fri Jun 27 14:52:21 EDT 2008


> In code that runs after the module has been imported (basically
> anything defined in a function that isn't called by code that runs at
> module time), you can expect the variables defined in the imported
> module to be available.
>
> If you have circular imports involved, making sure the modules import
> in a certain order can be quite hairy.  (Faced with this problem, I
> found it necessary to write an import hook to pre-import certain
> modules.)

Ok, thanks for all the advice: I now have the class architecture I was
looking for, by using much less specific imports, as Dan originally
suggested.

Re-factoring the use of partially loaded modules into functions wasn't
an option for me, unfortunately, as the classes were being used as
super classes or class variables. So, the code is a bit more verbose
than before, but works!

James



More information about the Python-list mailing list