lambda & scope

Randall Kern randy at teamkern.net
Sun Nov 5 21:25:03 EST 2000


try this:

def fred(scale):
    v = [1, 2, 3]
    v = map(lambda x, scale=scale: x * scale, v)

the lambda function has it's own scope, just like a normal def function.

-Randy

----- Original Message ----- 
From: "Johannes Zellner" <johannes at zellner.org>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Sunday, November 05, 2000 6:03 PM
Subject: lambda & scope


> Hi,
> 
> this fails:
> 
>     def fred(scale):
>         v = [1, 2, 3]
>         v = map(lambda x: x * scale, v)
> 
> NameError: There is no variable named 'scale'
> 
> how can I make it working ?
> 
> -- 
>    Johannes
> -- 
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list