Python critique
Octavian Rasnita
orasnita at gmail.com
Fri Dec 10 10:27:25 EST 2010
From: "Jean-Michel Pichavant" <jeanmichel at sequans.com>
>
> Octavian Rasnita wrote:
>> It is true that Python doesn't use scope limitations for variables?
>>
>> Octavian
>>
> Python does have scope. The problem is not the lack of scope, to
> problem is the shadow declaration of some python construct in the
> current scope.
It's OK then.
> print x # raise NameError
> [x for x in range(10)] # shadow declaration of x
> print x # will print 9
>
> it can become a problem if you write such code:
>
> index = 1
> myNewList = [index*2 for index in [1,2,3,4,5]]
> print myNewList(index) # here most new commer would want to use index=1.
Yes, it is not such a big deal.
Octavian
More information about the Python-list
mailing list