Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > eval with print stmt

Reply
Thread Tools

eval with print stmt

 
 
Art
Guest
Posts: n/a
 
      07-29-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
 
Reply With Quote
 
 
 
 
Mel Wilson
Guest
Posts: n/a
 
      07-29-2004
In article <(E-Mail Removed) >,
http://www.velocityreviews.com/forums/(E-Mail Removed) (Art) wrote:
>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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to return correct value of update stmt eight02645999@yahoo.com Python 2 10-19-2005 02:06 PM
PSL stmt embedded in VHDL: good tutorials somewhere? Eric DELAGE VHDL 2 04-06-2005 05:11 AM
AAA vs. pw on line stmt Cisco 1 02-28-2004 10:21 AM
AAA vs. pw on line stmt Cisco 0 02-27-2004 07:53 PM
How to pass special characters in Update stmt!! Jay ASP .Net 3 10-31-2003 12:30 AM



Advertisments