Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

Scott David Daniels scott.daniels at acm.org
Sat Jun 23 18:46:17 EDT 2007


vasudevram wrote:
> Hi group,
> 
> Question: Do eval() and exec not accept a function definition? (like
> 'def foo: pass) ?

def is the first keyword in a _statement_, not an expression.

exec executes statements, eval evaluates expressions.

try this:

     exec "def foolish(x):\n    y= x * 2\n    print x, y"
     foolish(2.4)


-- 
--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list