Guilty secret: globals baffle me

Edward K. Ream edream at tds.net
Wed Nov 6 09:43:11 EST 2002


The more I think about global variables, the more confused I get.

My app has only one "official" global variable, called gApp, and it never
seemed to work to set or access it directly, so I use app() and setApp()
functions to get and set it.  app() returns the singleton instance of a
class that represents the application itself, and I use ivars in this object
as surrogates for global vars.

This isn't bad, I suppose, but I am still totally baffled by globals.

My questions:

1. How many globals are there?  Is there just one, or does each module
define its own?

2. It seems that:

global foo
foo = x
...
global
print foo

only works if the two parts are within the same module, so I think maybe
globals() returns module specific stuff, but then why call it globals?

Can anyone shed some light on matters? Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------





More information about the Python-list mailing list