how to talk to __main__?

Justin Sheehy dworkin at ccs.neu.edu
Mon Feb 14 12:37:50 EST 2000


"Michal Wallace" <sabren at manifestation.com> writes:

> allDone = 0
> 
> def callback():
>     allDone = 1  # allDone is local, so this won't work
>     #__main__.allDone = 1 # gives an error
> 
> # assign callback() to external event here...
> 
> while not allDone:
>     pass
> 
> print "All done!"

As the eff-bot said, you could solve this by importing __main__, but
it's worth noticing that you don't have to resort to such namespace
trickery.

Just put the statement 'global allDone' at the front of your function
definition, and that name will refer to the corresponding global variable.

-Justin

 




More information about the Python-list mailing list