Problem with python 3.2 and circular imports

Frank Millman frank at chagford.com
Sun Feb 27 09:10:49 EST 2011


"Steven D'Aprano" <steve+comp.lang.python at pearwood.info> wrote in message 
news:4d6a56aa$0$29972$c3e8da3$5496439d at news.astraweb.com...
> On Sun, 27 Feb 2011 12:08:12 +0200, Frank Millman wrote:
>
>> Assume the following structure -
>>
>> main.py
>> /pkg
>>     __init__.py
>>     mod1.py
>>     mod2.py
>>
>> main.py
>>     from pkg import mod1
>>
>> mod1.py
>>     import mod2
>>
>> mod2.py
>>   import mod1
>
>
> If you change the "import mod*" lines to "import pkg.mod*" it works for
> me in Python 3.1 and 3.2.
>
> According to my understand of PEP 328, "from . import mod*" should work,
> but I agree with you that it doesn't.
>
> If you get rid of the circular import, it does work. So I suspect a bug.
>
>

Thanks, Steven.

I confirm that 'import pkg.mod* works. Unfortunately I am using sub-packages 
as well, which means that to refer to an object in the sub-package I need to 
use w.x.y.z every time, which gets to be a lot of typing! I will stick to my 
hack of putting the package name in sys.path for now, unless someone comes 
up with a better idea.

Frank





More information about the Python-list mailing list