properties vs. eval()

Michael Hoffman cam.ac.uk at mh391.invalid
Wed May 4 19:27:56 EDT 2005


Peter Otten wrote:

> Use 
> 
> eval(s) 
> 
> to evaluate an expression and 
> 
> exec s
> 
> to execute a statement.

I never thought of using compile() to get around this before. Now I can 
finally use print in my lambda functions! Just think of the horrible 
code I could write:

f = lambda x: eval(compile("print %s" % x, "<string>", "exec"))
-- 
Michael Hoffman



More information about the Python-list mailing list