ENC: lambda question
Alves, Carlos Alberto - Coelce
calves at coelce.com.br
Mon Mar 11 13:07:03 EST 2002
See the error below:
>>> def exe1(f,list):
return map(lambda x:eval(f),list)
SyntaxError: local name 'f' in 'exe1' shadows use of 'f' as global in nested
scope 'lambda' (<pyshell#7>, line 1)
>>>
> -----Mensagem original-----
> De: Bertrand Geston [mailto:bergeston at yahoo.fr]
> Enviada em: segunda-feira, 11 de março de 2002 14:46
> Para: python-list at python.org
> Assunto: Re: lambda question
>
>
> lambda questionBoth work on my computer:
>
> PythonWin 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit
> (Intel)] on win32.
> Portions Copyright 1994-2001 Mark Hammond
> (mhammond at skippinet.com.au) - see
> 'Help/About PythonWin' for further copyright information.
> >>> def exe1(f,list):
> ... return map(lambda x:eval(f),list)
> ...
> >>> f='x**3+2*x'
> >>> list=[0,1,2,0]
> >>> map(lambda x:eval(f),list)
> [0, 3, 12, 0]
> >>> exe1(f,list)
> [0, 3, 12, 0]
> >>>
>
> If you give us the kind of error, problem hou have, you will
> help us to help
> you.
> TIA ;-)
>
> "Alves, Carlos Alberto - Coelce" <calves at coelce.com.br> wrote
> in message
> news:mailman.1015866267.21439.python-list at python.org...
> Hi all,
> Look at the two codes below
> first code:
> f='x**3+2*x'
> list=[0,1,2,0]
> map(lambda x:eval(f),list)
> second code:
> def exe1(f,list):
> return map(lambda x:eval(f),list)
> Can someone explain to me why the first code works while
> second doesn't.
> Carlos Alberto
> COELCE/DPRON-Departamento de Projetos e Obras Norte
> Fone: 677- 2228
> e-mail: calves at coelce.com.br
> \|||/
> (o o)
> --ooo0-(_)-0ooo--
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020311/f70657a8/attachment.html>
More information about the Python-list
mailing list