Cycles between package imports

Martin Blais blais at
Wed Jun 21 07:41:44 CEST 2006

On 18 Jun 2006 05:25:14 -0700, John Roth <JohnRoth1 at> wrote:
> Martin Blais wrote:
> > Hi
> >
> > I'm a tad confused over a problem involving cycles between
> > packages.
> [lengthy  example snipped]
> >
> >
> > I don't see why the reference to module a.alice could not be
> > available via the "from" syntax, even if it is still incompletely
> > initialized at the time of import.
> >
> > Can anyone shed some light onto this?  Is there a rule for
> > determining when a module becomes available to import from a
> > package using the "from" syntax?
> It's really easy to see if you trace out, in detail, the exact
> order in which things happen and when each object is initialized and
> shows up in the respective module's  namespace.

No it's not, at least I don't see it.   The order in which the symbols
appear is different whether you're using the simple "import" form or
the "from ... import" form.  This is exactly what the question is

> The general rule is: don't do that. It doesn't work, and the
> hoops you have to go through to force it to work are so
> complex and bizzare that they're not worth it.  Redesign
> the modules so you don't have cyclic dependencies.

This is a matter completely aside the question.  Whether it's worth it
or not depends on the specific case --not included in the example--
and in the case where it shows up in my code, removing the cycle
actually made sense (it does, most of the time, but not always).


More information about the Python-list mailing list