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

Discussion in 'Python' started by Fredrik Lundh, Nov 3, 2006.

  1. Fredrik Lundh, Nov 3, 2006
    #1
    1. Advertising

  2. Fredrik Lundh

    robert Guest

    Fredrik Lundh wrote:
    > Hendrik van Rooyen wrote:
    >
    >> I am struggling with this - I want to define a "system-wide" flag for
    >> use as a
    >> semaphore.

    >
    > 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



    -robert
    robert, Nov 3, 2006
    #2
    1. Advertising

  3. "robert" <> wrote:


    > Fredrik Lundh wrote:
    > > Hendrik van Rooyen wrote:
    > >
    > >> I am struggling with this - I want to define a "system-wide" flag for
    > >> use as a
    > >> semaphore.

    > >
    > >

    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
    >
    >
    > -robert


    Thanks - how could you possibly have guessed that I am lazy - does it show that
    much? *WEG*

    - Hendrik
    Hendrik van Rooyen, Nov 4, 2006
    #3
  4. Fredrik Lundh

    alex23 Guest

    Hendrik van Rooyen wrote:
    > "robert" <> 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
    alex23, Nov 6, 2006
    #4
  5. "alex23" <> wrote:

    > Hendrik van Rooyen wrote:
    > > "robert" <> 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
    Hendrik van Rooyen, Nov 6, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MackS
    Replies:
    1
    Views:
    289
    Patrick Maupin
    Sep 10, 2005
  2. Hendrik van Rooyen
    Replies:
    0
    Views:
    215
    Hendrik van Rooyen
    Nov 3, 2006
  3. bdb112
    Replies:
    45
    Views:
    1,317
    jazbees
    Apr 29, 2009
  4. Replies:
    6
    Views:
    372
    Thomas 'PointedEars' Lahn
    Apr 25, 2012
  5. chandan kumar

    global variable across modules

    chandan kumar, Sep 11, 2013, in forum: Python
    Replies:
    0
    Views:
    117
    chandan kumar
    Sep 11, 2013
Loading...

Share This Page