The imp module and cyclic imports

Matthias Kramm m.kramm at quiss.org
Sun Nov 27 08:03:30 EST 2005


> the problem you're seeing appears also if you use "import web.one"
> or "from web import one" or "__import__('web.one')".

Thanks for the hint. You're right. This isn't actually imp related. The
standard import also fails.

> if you replace the "from web import" statements with plain imports,
> everything will work as expected.  just change
>
>    from web import one
>
> to
>
>   import one

Unfortunately, this fails if one.py and two.py are in different
directories/packages.
With a setup like
web1/one.py
web2/two.py
there doesn't seem to be any way to make one.py and two.py reference
each other via (non-delayed) imports.

It's interesting, though, that cyclic imports work when using the plain
"import foo" import, but not with the "from package import foo" style.
Especially since the former also used to fail (google for "python
cyclic imports" on groups.google.com). I wonder whether the "from"
style imports were overlooked when the cyclic problem was fixed.

Greetings

Matthias




More information about the Python-list mailing list