question on global variables
tdelaney at avaya.com
Thu Oct 10 07:02:21 CEST 2002
> From: mongo57a at comcast.net [mailto:mongo57a at comcast.net]
> I see that there is a "global" command - and I assume its use would be
> global var_name. This I have coded (works) but I am unable to
> use it "global
> name var_name is not defined".
The 'global' statement tells a function to use a name in its module
namespace, rather than its local namespace.
There is one completely global namespace in python - if a name is not found
in the module namespace, then the namespace of the __builtin__ module is
It is considered *very* bad form to stick things in the __builtin__ module.
It is generally considered bad form to use the 'global' statement - it
usually means that your design needs more work.
There are of course exceptions to the above two statements, but you should
really understand python namespaces completely first. FWIW, I have *never*
used the 'global' statement in python, and I've only played with __builtin__
when doing some pretty funky stuff ;)
More information about the Python-list