global variable not seen (bug?)
Cliff Wells
LogiplexSoftware at earthlink.net
Wed Jan 8 15:06:27 EST 2003
On Wed, 2003-01-08 at 09:03, Skip Montanaro wrote:
> Michal> ---imported.py start---
> Michal> def someFunction():
> Michal> global GLOBAL_VARIABLE
>
> Michal> print GLOBAL_VARIABLE
> Michal> ---imported.py end---
>
> Somebody still has to actually assign a value to that name. All the global
> declaration does is tell the system that if you assign a value to the
> variable to put it in the global scope of the module, not the local scope
> (the function). This would work:
>
> GLOBAL_VARIABLE = None
> def someFunction():
> print GLOBAL_VARIABLE
If you read the OP's entire post (particularly the cut&paste from the
interactive Python session) you'll see that he in fact did assign to
GLOBAL_VARIABLE. It just wasn't in the module that actually used it.
The problem is that "globals" aren't really. They are global only to
the module they were defined in.
To the OP: please don't use globals like this, even in languages that
allow it. Modules that depend upon a global variable being defined in a
different module are not modulular. Besides, anyone working on the code
later will hate you and make disparaging comments about your competence
in the source. Further, it'll be deserved.
Globals-bite-large-chunks-of-ass'ly yrs,
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308
More information about the Python-list
mailing list