eval() and local variables

Peter Luciak peter at luciak.org
Tue Apr 20 04:04:20 EDT 2004


Hi,
I need to do something like this:

def my():
        a,b=1,2
        func = "lambda x: a*x+b"
        map(eval(func),[1,2,3])

my()

NameError: global name 'a' is not defined

Why do I have to make a,b global for this to work?

Thanks,
P.
-- 
Peter `cuco' Luciak 		jabber://cuc0@jabber.sk
peter at luciak.org 		http://www.luciak.org/




More information about the Python-list mailing list