Is there a way to define a true global across modules?

Hendrik van Rooyen mail at microcorp.co.za
Mon Nov 6 07:48:03 CET 2006


 "alex23" <wuwei23 at gmail.com> wrote:

> Hendrik van Rooyen wrote:
> > "robert" <no-spam at no-spam-no-spam.invalid> wrote:
> > > Fredrik Lundh wrote:
> > > >
http://www.effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm
>
> > > Or worse style - if you are too lazy to create a extra global variables
module
> > > (ab)use the __main__ module als "global":
> > > import __main__
> > > __main__.mysemphore += 1
>
> > Thanks - how could you possibly have guessed that I am lazy - does it show
that
> > much?  *WEG*
>
> You could merge the two approaches and bind a more explicit name to
> __main__:
>
> import __main__ as config
>
> config.mysemaphore = 0
>
> It's a little clearer what you're subverting __main__ for here :)
>
> - alex23

Thanks - clever and clear!

- Hendrik




More information about the Python-list mailing list