[Tutor] global statement?

Rob Andrews rob@jam.rr.com
Wed, 15 Aug 2001 09:23:17 -0500


> Now that's interesting. I didn't realize global would have
> that effect, I expected a name error on the assignment.
> Instead it simply creates a new name in the global namespace.
> 
> I still don't like it as a matter of style but I'm interested
> that it does work and in fact creates new variables in the
> imported modules namespace if placed in a module...
> 
> Now, is that better than doing
> 
> import foo
> foo.a = 56
> 
> ??? I'm not sure.
> I'm off to ponder.
> 
> Alan G
> 

*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."

stumped,
Rob
-- 
A {} is a terrible thing to waste.
Useless Python!
http://www.lowerstandard.com/python