Problem with modules refering to each other

Klaus Alexander Seistrup kas at maps.magnetic-ink.dk
Sun Aug 8 09:29:04 EDT 1999


Phil Hunt wrote:

>>>    #bak.py
>>>    from hhh import *
>>>
>>> [...]
>>> 
>>>    #hhh.py
>>>    from bak import *
>> 
>> Do we have a circular reference here?
> 
> Yes. Does Python not allow this? What's the workaround?

It seems python allows it, however, in this case it is not beneficial.
See, bak tells the interpreter to get all of hhh before proceeding but
as soon as python goes there it is told to go back and get the rest of
bak.  At least thats how I perceive it.

I do not know the details of your code, so I cannot be sure, but a
workaround may have to include the creation of a third module and/or
repositioning the import statement(s) -- it's not a law that they have
to appear at the beginning, but sometimes it gives you a better over-
view.

I would try and reposition the the import statements first, then,
if this doesn't work, creating a third module and rearraniging things
so as to avoid circular references.

Let us know what you find out. :-)


  //Klaus

-- 
···[ Magnetic Ink ]················································· ><> ···
···[ Delapsus resurgam ]····················································




More information about the Python-list mailing list