eval with print stmt
Art
abrady at prontomail.com
Thu Jul 29 17:08:49 EDT 2004
Hello,
I can't seem to get eval or compile to accept the print stmt, or any
complicated statements.
The documentation I've looked out doesn't explain why this is.
ex:
>>> eval("print('foo')")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1
print('foo')
but this works:
>>> eval('sys.__stdout__.write("foo\\n")')
foo
also, I can't get eval to make callable objects. is this possible?
>>> eval("def foo():\n return 'foo'")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1
def foo():
^
SyntaxError: invalid syntax
I'd like to have a command line parameter be turned into a callable
statement with an expected environment (a la awk) but I can't seem to
get this working. (I get the same behavior for compile.
Thanks,
A
More information about the Python-list
mailing list