[Python-3000] Sky pie: a "var" keyword

Neil Toronto ntoronto at cs.byu.edu
Mon Oct 9 19:58:51 CEST 2006


Fredrik Lundh wrote:
> Neil Toronto wrote:
>
>   
>> A "var" keyword fixes them all. The "global" gotcha:
>>
>> x = 0
>> def f():
>>    print x   # no exception - prints "0"
>>    x = 3
>>
>> def g():
>>    print x   # exception
>>    var x = 3
>>     
>
> what are the exact semantics of "var" ?  are you saying that local variables
> should be global by default?
>   

Heck no. An assignment would modify an existing variable only. A "var" 
in front of a variable name would put the variable in the local dictionary.

Also, the example needs "var x = 0" in the global scope - that was a 
mistake on my part.

Neil



More information about the Python-3000 mailing list