Circular Import?

Chris S. chrisks at NOSPAM.udel.edu
Sat Aug 28 05:09:12 EDT 2004


Consider the sample case:

## a.py
import d
import b
b.App()

## b.py
from c import C
B = 'B'
class App(object):pass

## c.py
from d import D
class C(object):pass

## d.py
from b import B
D = 'D'

Executing a.py will return:
Traceback (most recent call last):
   File "a.py", line 1, in ?
     import d
   File "d.py", line 1, in ?
     from b import B
   File "b.py", line 1, in ?
     from c import C
   File "c.py", line 1, in ?
     from d import D
ImportError: cannot import name D

I'm assuming this is the result of the circular imports. This isn't a 
bug, right? Is there any way around it?



More information about the Python-list mailing list