Accessing variables created after import in imported files

Darrell news at dorb.com
Mon Jan 1 09:53:31 EST 2001


Hi Jesse

My take on this is that you have a mutual dependency to remove.
One possible solution:  Don't let file1 and file2 import each other.

Create file3:
import file1, file2

TheGame=file1.Game()
foo = file2.ThingThatUsesGameClass(TheGame)

--Darrell


"Jesse W" wrote:
> Dear Scott,
> Thank you very much, your solution works quite well.  I wonder why I
> did not think of it myself, or why I was so folish as to reject it when
> I had it.  But, now I am faced with another strange and puzzinling
> probblem; however, this one I have found a solution for, but I have no
> idea _why_ the solution works.  When I run the code I wrote up, with
> your change, it gives an AttributeError on the use of
> ThingThatUsesGameClass in file1.  However, if you reload file2 after
> importing it, then the code works perfectly.  Why?  How?  This makes no
> sense!  As far as I knew, importing and reloading were identical, as
> long as the file was unchanged.  Do you have any ideas about why this
> could be?
>
> Thank you for your solution,
> Jesse W
>






More information about the Python-list mailing list