Please consider that example:
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright" , "credits" or "license" for more information.
'foo'
'bar'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in <lambda>
NameError: global name 's' is not defined
It seems to me, that f is referencing the name s instead of the string
object bound to it
i would expect the analogous behaviour to the following example:
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright" , "credits" or "license" for more information.
'foo'
'foo'
I could work around this but I am interested why there is that
difference.
Leonhard
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright" , "credits" or "license" for more information.
>>s = 'foo'
>>f = lambda x: s
>>f(None)
>>f = lambda x: s
>>f(None)
>>s = 'bar'
>>f(None)
>>f(None)
>>del(s)
>>f(None)
>>f(None)
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in <lambda>
NameError: global name 's' is not defined
It seems to me, that f is referencing the name s instead of the string
object bound to it
i would expect the analogous behaviour to the following example:
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright" , "credits" or "license" for more information.
>>s = 'foo'
>>f = s
>>f
>>f = s
>>f
>>s = 'bar'
>>f
>>f
I could work around this but I am interested why there is that
difference.
Leonhard
Comment