problem with 'global'

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jan 21 14:08:46 EST 2008


En Mon, 21 Jan 2008 11:44:54 -0200, Mel <mwilson at the-wire.com> escribi�:

> Duncan Booth wrote:
>>
>> The first sentence (which hasn't changed since 2.4) describing the  
>> global
>> statement seems clear enough to me: "The global statement is a  
>> declaration
>> which holds for the entire current code block."
>
> I don't think that would stop the OP from thinking the global
> statement had to be executed.  In the code example, it seems to have
> been stuck in a
>
>      if 1==2: global a
>
> and it still worked.

The future statement is another example, even worse:

if 0:
     from __future__ import with_statement

with open("xxx") as f:
     print f

All import statements are executable, only this special form is not. That  
"global" and "__future__" are directives and not executable statements, is  
confusing.

-- 
Gabriel Genellina




More information about the Python-list mailing list