Accessing variables created after import in imported files

Scott David Daniels Scott.Daniels at Acm.Org
Mon Jan 1 00:56:05 EST 2001


Try:
    ...
    #file 2
    import file1

    class ThingThatUsesGameClass:
       def __init__(self):
           print file1.TheGame.foo #this should use the instance of the Game
#class
    ...

"Jesse W" <jessw at loop.com> wrote in message news:3A4FFBCB.76A7 at loop.com...
> Sorry about the somewhat unclear subject line.  I am not totally sure
> of the general form of my problem, so it is hard to write it as a
> subject line.  My problem involves a program I am writting to allow
> people to play a really fun card game I know, Hot Death Uno.  Insted of
> posting the actual code(It's really long, and even snipits would be
> pretty complex) I have enclosed code which demostrates the problem, but
> is not the actual code I am working with.  If someone want's to see it,
> I would be glad to e-mail it to them.
> The code is in two files:
> #file 1
> import file2
>
> class Game:
>     def __init__(self):
> global TheGame
> TheGame=self
> #this lets other classes access the current
>   #instence of the game without knowing the name it was
> #created as.
> self.foo='Some random variable'
> x=Game()
> foo=file2.ThingThatUsesGameClass()
>
> #file 2
> import file1
>
> class ThingThatUsesGameClass:
>     def __init__(self):
> print TheGame.foo #this should use the instance of the Game #class
> created in the other file.
>
>
> Thank you very much for your time,
> Jesse Weinstein





More information about the Python-list mailing list