variable declaration

Brian van den Broek bvande at po-box.mcgill.ca
Tue Feb 8 11:55:07 EST 2005


Brian van den Broek said unto the world upon 2005-02-07 20:36:
> Steve Holden said unto the world upon 2005-02-07 17:51:

<SNIP>

>> The reason global is a wart can clearly be seen in the following example:
>>
>>  >>> x = 3
>>  >>> def f(tf, v):
>>  ...   if tf:
>>  ...     global x
>>  ...   x = v
>>  ...
>>  >>> f(0, 5)
>>  >>> x
>> 5
>>  >>>

<SNIP>

> Hi,
> 
> Steve's example makes my brain hurt. :-)
> 
> I'd appreciate it if someone could tell me if I am understanding the 
> example correctly. (My grasp of the terminology and issues at play is a 
> bit shaky.)

<SNIP>

> Thanks for any confirmation of my understanding / rectification of same. 
> Best,
> 
> Brian vdB

Thanks to everyone whose contributed to this sub-thread! I've learned 
a lot. :-)

And, for posterity, some one wrote me off-list to correct my claim
that in

if False:
     # thousands of lines of code here

the thousands of lines "would never get executed". Simplifying their 
example, they pointed out:

 >>> False = 'evil trickery'
 >>> if False:
...     print 'Surprise!'
...
Surprise!
 >>>

Which leads me naturally to the differences between 'if False:' and 
'if ):' that Duncan Booth pointed to. (Where'd I put the Tylenol.)

Thanks again to all,

Brian vdB





More information about the Python-list mailing list