Lambda?!

Mark McEahern marklists at mceahern.com
Tue Aug 20 10:26:37 EDT 2002


> Python 2.0 (#1, Jan 19 2001, 17:54:27) 
> [GCC 2.95.2 19991024 (release)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> class foo:
> ...     def bar(self, a):
> ...             return "<%s>" % a
> ...     def spam(self):
> ...             return map(lambda rope: self.bar(rope).upper(), 
> ['test', 'other test'])
> ... 
> >>> f = foo()
> >>> f.spam()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 5, in spam
>   File "<stdin>", line 5, in <lambda>
> NameError: There is no variable named 'self'

I added:

  import sys
  print sys.version

and changed the last line to:

  print f.spam()

and got:

  2.2.1 (#1, Jun 25 2002, 10:55:46)
  [GCC 2.95.3-5 (cygwin special)]
  ['<TEST>', '<OTHER TEST>']

So, a more accurate subject would be:

  Lambda with Python 2.0 and/or nested scopes?!

<wink>

// m

-





More information about the Python-list mailing list