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


Groups > comp.lang.python > #20961

Re: Question about circular imports

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'am,': 0.12; 'a.py': 0.16; 'c.py': 0.16; 'etc?': 0.16; 'identifier': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'subject:Question': 0.19; 'jan': 0.19; '(most': 0.21; 'header:In- Reply-To:1': 0.22; 'traceback': 0.24; 'work.': 0.27; 'import': 0.27; 'tried': 0.27; 'does': 0.32; 'that,': 0.32; 'error.': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'object': 0.33; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'last):': 0.34; 'to:addr:python-list': 0.35; 'something': 0.35; 'received:org': 0.36; 'run': 0.37; 'but': 0.37; 'skip:" 10': 0.37; 'difference': 0.38; 'some': 0.38; 'to:addr:python.org': 0.40; 'follow': 0.61; 'choose': 0.64; 'frank': 0.64; 'notice.': 0.96
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Question about circular imports
Date Mon, 27 Feb 2012 20:01:05 -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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <jif74e$j1l$1@dough.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.211.1330390886.3037.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330390886 news.xs4all.nl 6846 [2001:888:2000:d::a6]:38380
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20961

Show key headers only | 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