Problem with global variables

Steve Holden steve at holdenweb.com
Mon Apr 2 10:38:53 EDT 2007


Bjoern Schliessmann wrote:
> Laurent Pointal wrote:
> 
>> And so the solution to add "global foo" before using it.
> 
> Didn't you read his final question?
> 
> | All of a sudden, tiny() can see the global variable "foo".  Very
> | confusing!  Why is it that tiny() sometimes can, and sometimes
> | can't, see the global variable "foo"?
> 
> I have no explanation for this, but I'm interested in one, too.
> 
It doesn't happen "all of a sudden", it happens when the assignment to 
foo is removed from the function definition. The interpreter therefore 
no longer regards foo as a local variable.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list