Accessing variables created after import in imported files

Jesse W jessw at loop.com
Mon Jan 1 03:12:55 EST 2001


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

Scott David Daniels wrote:
> 
> Try:
>     ...
>     #file 2
>     import file1
> 
>     class ThingThatUsesGameClass:
>        def __init__(self):
>            print file1.TheGame.foo #this should use the instance of the Game
> #class
>     ...
>



More information about the Python-list mailing list