Circular import problem
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Jul 12 23:08:06 EDT 2007
En Thu, 12 Jul 2007 23:36:16 -0300, bvdp <bob at mellowood.ca> escribió:
> I'm going quite nutty here with an import problem. I've got a fairly
> complicated program (about 12,000 lines in 34 modules). I just made
> some "improvements" and get the following error:
>
> bob$ mma
> Traceback (most recent call last):
> File "/usr/local/bin/mma", line 55, in <module>
> import MMA.main
> File "/usr/local/share/mma/MMA/main.py", line 33, in <module>
> import MMA.docs
> File "/usr/local/share/mma/MMA/docs.py", line 34, in <module>
> import MMA.grooves
> File "/usr/local/share/mma/MMA/grooves.py", line 41, in <module>
> import MMA.auto
> File "/usr/local/share/mma/MMA/auto.py", line 35, in <module>
> import MMA.parse
> File "/usr/local/share/mma/MMA/parse.py", line 2052, in <module>
> 'AUTHOR': MMA.docs.docAuthor,
> AttributeError: 'module' object has no attribute 'docs'
>
> I can fix this by deleting a line in docs.py. Just take out the
> "import MMA.grooves" and all works. What I really don't get is that in
> the middle of this module which is now NOT loading "grooves.py" I have
> a command to access a function in that module and it works.
>
> Yes, grooves.py has an import docs.py. And there are lots of other
> such imports in the program.
>
> So, I have to assume that the error is being generated by some other
> modules loading in the grooves.py stuff ... but really have no idea.
>
> Is there anything I can do to trace though this and get it working
> properly?
See http://effbot.org/zone/import-confusion.htm
Try to move the circular references later in the code (maybe inside a
function, when it is required), or much better, refactor it so there is no
circularity.
--
Gabriel Genellina
More information about the Python-list
mailing list