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

Discussion in 'Python' started by Hendrik van Rooyen, Nov 3, 2006.

  1. I am struggling with this - I want to define a "system-wide" flag for use as a
    semaphore.

    It looks to me as if the only way to do it is to import all the modules that
    need to access it into the main namespace using the " from whatever import * "
    form.

    Is there a way to have one global object known to the main module as well as say
    two imported modules by using the global statement in the three places, while
    using the normal "import modname " form?

    It looks as if the global statement just makes the name global to the module
    where it is defined, and if I use the "import modname" form I end up with a
    "local global" for each module, as well as one for the main module...

    Can they be "merged' into one without sticking everything into the same
    namespace?

    I can think of ways to work around this, but it gets a bit obfuscatory - it
    would be nicer to have one name, one thing in all three places...

    - Hendrik
     
    Hendrik van Rooyen, Nov 3, 2006
    #1
    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:
    293
    Patrick Maupin
    Sep 10, 2005
  2. Fredrik Lundh
    Replies:
    4
    Views:
    228
    Hendrik van Rooyen
    Nov 6, 2006
  3. bdb112
    Replies:
    45
    Views:
    1,346
    jazbees
    Apr 29, 2009
  4. Replies:
    6
    Views:
    379
    Thomas 'PointedEars' Lahn
    Apr 25, 2012
  5. chandan kumar

    global variable across modules

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

Share This Page