Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20961

Re: Question about circular imports

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Question about circular imports
Date 2012-02-27 20:01 -0500
References <jid2a9$n21$1@dough.gmane.org> <jid424$vfp$1@dough.gmane.org> <jieaid$e4k$1@dough.gmane.org> <jif74e$j1l$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.211.1330390886.3037.python-list@python.org> (permalink)

Show all headers | View raw


On 2/27/2012 1:16 AM, Frank Millman wrote:
>>
>> To avoid the tedious reference, follow this with
>> read = sound.formats.wavread # choose the identifier you prefer

I tested something like this with stdlib, but there must be some 
important difference I did not notice. It make be in the contents of 
__init__.py.

> @Terry and OKB
>
> I tried that, but it does not work.
>
> a.py
> /b
>      __init__.py
>      c.py
>     d.py
>
> a.py -
>      from b import c
> c.py -
>      import b.d
> d.py -
>      import b.c

How about import b.d as d, etc?

> If I run a.py, it returns with no error.
>
> c.py -
>      import b.d
>      d = b.d
> d.py -
>      import b.c
>      c = b.c
>
> If I run a.py, I get
>
> Traceback (most recent call last):
>    File "F:\tests\a.py", line 1, in<module>
>      from b import c
>    File "F:\tests\b\c.py", line 1, in<module>
>      import b.d
>    File "F:\tests\b\d.py", line 2, in<module>
>      c = b.c
> AttributeError: 'module' object has no attribute 'c'
>
> I get the same if I try 'import b.c as c'.

Try import b; c = b.c


-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about circular imports Terry Reedy <tjreedy@udel.edu> - 2012-02-27 20:01 -0500

csiph-web