Creating a local variable scope.

Lie Ryan lie.1296 at gmail.com
Mon Nov 30 04:30:16 EST 2009


On 11/30/2009 8:13 PM, markolopa wrote:
> On Nov 30, 4:46 am, Dave Angel<da... at ieee.org>  wrote:
>> markolopa wrote:
>>> Antoher 15 minutes lost because of that Python "feature"... Is it only
>>> me???
>>
>> Yep, I think so.
>
> Not very consoling but thanks anyway!...:-))))
>
>>   You're proposing a much more complex scoping rule,
>> where if a variable already exists before entering a loop, then the loop
>> uses that existing variable, but if not, it creates its own local one
>> and destroys it when exiting the loop.
>
> Alternatively you could forbid the creation of a variable in a inner
> block if it already exists. Either that or forbid the usage of the
> variable in an outter block later if it exists both in an inner and
> outer block.
>

Of course, the best solution would be to allow assignment only in a 
single line of source of code. Reassignment by different lines of code 
would be a syntax error. You're forced to have different names if you 
want assign something multiple times. That way, no bugs is possible.



More information about the Python-list mailing list