Unqualified global vars, how?

Discussion in 'Python' started by Christopher J. Bottaro, Oct 25, 2004.

  1. >From the python programming FAQ, I learned you can do this:

    Globals.py:
    gv = 1

    A.py:
    import Globals
    class A:
    def __init__(self):
    print Globals.gv
    Globals.gv += 1

    B.py:
    import Globals
    class B:
    def __init__(self):
    print Globals.gv
    Globals.gv += 1

    main.py:
    import A
    import B
    a = A.A()
    b = B.B()

    That will print:
    1
    2
    and Globals.gv will have a final value of 3.

    I want access to gv without having to qualify it with Globals. I tried
    saying:

    A.py:
    from Globals import gv
    class A:
    def __init__(self):
    print gv
    gv += 1

    But python complains that gv isn't defined yet. Is what I want to do
    possible? I just want one module (file) with a bunch of globals vars and
    to able to access those global vars without qualify them the module name.

    Thanks for the help.
     
    Christopher J. Bottaro, Oct 25, 2004
    #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. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    419
  2. C. M. Sperberg-McQueen
    Replies:
    0
    Views:
    964
    C. M. Sperberg-McQueen
    Jul 31, 2003
  3. Mavis
    Replies:
    1
    Views:
    347
    Mavis
    Jun 2, 2006
  4. Linuxguy123
    Replies:
    7
    Views:
    721
    Paddy O'Loughlin
    Feb 20, 2009
  5. caccolangrifata
    Replies:
    18
    Views:
    422
    Chris Torek
    Jul 22, 2011
Loading...

Share This Page