global declaration from within functions

Aahz Maruch aahz at panix.com
Tue Aug 21 12:44:06 EDT 2001


In article <3B7A87D8.6F75B13F at jam.rr.com>, Rob Andrews  <rob at jam.rr.com> wrote:
>
>*Learning Python* (pp. 99-105) points out that declaring globals from
>within functions is possible, and shows how. I'm trying to think of
>*why* one might want to declare or modify a global from within a
>function.
>
>A friend who knows quite a bit more than I do about the subject said:
>"That's the first thing about python I've seen that really makes me go
>"yecchhh.".  Global variables have to be declared outside the scope of
>any functions or methods in almost every langauge except Perl."

Side note: global names (I prefer to use "name" instead of "variable")
are not truly global in Python; they are only global within a module
namespace.  The only way to get a truly global name is to hack the
builtins module.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

"I now regard a fact as a hypothesis that people don't bother to argue
about anymore."  --John Burn, quoted in Lawrence Wright's _Twins_



More information about the Python-list mailing list