Question about circular imports

Frank Millman frank at chagford.com
Mon Feb 27 07:16:47 CET 2012


>
> To avoid the tedious reference, follow this with
> read = sound.formats.wavread # choose the identifier you prefer
>

@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

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'.

Frank






More information about the Python-list mailing list