New syntax for blocks

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Nov 12 21:37:48 CET 2009


r a écrit :
> On Nov 11, 2:37 am, Steven D'Aprano
> <ste... at REMOVE.THIS.cybersource.com.au> wrote:
>> On Wed, 11 Nov 2009 00:08:58 -0800, r wrote:
> 
>>> Yea it's called a NameError. Would it not also blow up in the current
>>> state of syntax usage?
>> No.
>>
>>> if var:
>>>     print 'var'
>>> Traceback (most recent call last):
>>>   File "<pyshell#45>", line 1, in <module>
>>>     if var:
>>> NameError: name 'var' is not defined
>> You missed a line:
>>
>> var = range(N)
>> if var:
> 
> Oh i get it now! If i assign a valid value to a variable the variable
> is also valid...thats...thats... GENUIS! *sarcasm*

It's not about "assigning a valid value to a variable", it's about the
name being created (or not) in the current namespace, whatever it's
bound to.




More information about the Python-list mailing list