On Sun, 24 Jun 2007 11:17:40 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sat, 23 Jun 2007 19:58:32 +0000, vasudevram wrote: > >> >> Hi group, >> >> Question: Do eval() and exec not accept a function definition? (like >> 'def foo: pass) ? > >eval() is a function, and it only evaluates EXPRESSIONS, not code blocks.
Actually, that's not exactly true: >>> x = compile('def foo():\n\tprint "hi"\n', '<stdin>', 'exec') >>> l = {} >>> eval(x, l) >>> l['foo']() hi >>> Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list