A simple (newbie) question.

D-Man dsh8290 at rit.edu
Wed Feb 21 18:10:06 CET 2001


On Mon, Feb 19, 2001 at 08:08:42PM +0000, David A. wrote:
| Hello to everyone,
| 
|     maybe I have already sent this question to the group, but I am not sure
| (the first one never reached the group I think). Anyway, I am a newbie, so
| probably my question is a realy simple for the most experienced python
| users.
| 
| Well what I want to is this:
| >>> a='python'
| >>> b='print'
| >>> c=b+a
| >>> eval(c)
| Traceback (innermost last):
|   File "<pyshell#19>", line 1, in ?
|     eval(c)
|   File "<string>", line 1
|     print"python"
|         ^
| SyntaxError: invalid syntax

Try this to find the problem :

>>> print c
printpython


Once you check the data you are sending to eval you know that

printpython

is indeed invalid syntax.  Instead, try this:

a = '"python"'
b = 'print'
c = b + ' ' + a
eval( c )


HTH,
-D






More information about the Python-list mailing list