Unqualified global vars, how?

Jeff Epler jepler at unpythonic.net
Mon Oct 25 22:57:13 CEST 2004

Python won't do what you're asking for.

In your example code, "gv" is a local in A's __init__ function.

If you write
    from Globals import gv
    class A:
        def __init__(self):
            global gv
            print gv
            gv += 1
the code will execute, but the line
    gv += 1
only re-binds gv in A, it doesn't change Globals.gv or the value bound
to gv in any other module that executed the code 'from Globals import

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041025/d6e17b7c/attachment.pgp>

More information about the Python-list mailing list