Accessing variables created after import in imported files

Jesse W jessw at loop.com
Mon Jan 1 13:44:03 EST 2001


Dear Darrell, 
	Thank you.  If I seperate the executing code from the definitions, it
works.  But what is a mutual dependency, and why should that cause a
class to not appear when it is first imported?
						Thank you,
							Jesse Weinstein

Darrell wrote:
> 
> 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:
> > 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