Re: unexpected behaviour of lambda expression

2006-10-09 Thread leonhard . vogt
Fredrik Lundh schrieb: > [EMAIL PROTECTED] wrote: > > > 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. > s = 'foo' > f = lambda x: s > f(N

Re: unexpected behaviour of lambda expression

2006-10-09 Thread Duncan Booth
[EMAIL PROTECTED] wrote: f = lambda x: s ... f(None) > Traceback (most recent call last): > File "", line 1, in ? > File "", line 1, in > 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 Of co

Re: unexpected behaviour of lambda expression

2006-10-09 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > 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. s = 'foo' f = lambda x: s f(None) > 'foo' s = 'bar' f(None)

unexpected behaviour of lambda expression

2006-10-09 Thread leonhard . vogt
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. >>> s = 'foo' >>> f = lambda x: s >>> f(None) 'foo' >>> s = 'bar' >>> f(None) 'bar' >>> del(s) >>> f(None) Traceback (m