how to talk to __main__?

Fredrik Lundh effbot at telia.com
Mon Feb 14 12:49:16 EST 2000


Justin Sheehy <dworkin at ccs.neu.edu> wrote:
> "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.

unless the callback function is defined in another module,
of course.

</F>





More information about the Python-list mailing list