eval with print stmt

A

Art

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:Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1
print('foo')

but this works:foo

also, I can't get eval to make callable objects. is this possible?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
 
M

Mel Wilson

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.

eval only works with expressions, and `print ...` is a statement.
So is `def ...` .

exec should do what you want.

Regards. Mel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top