No subject

Jeff McNeil jeff at jmcneil.net
Tue Dec 11 20:09:17 EST 2007


>>> a = '[1,2,3,4]'
>>> b = 'Tropical Islands'
>>> eval(a)
[1, 2, 3, 4]
>>> eval(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1
    Tropical Islands
                  ^
SyntaxError: unexpected EOF while parsing
>>>


For eval to work, your string has to contain a valid python statement.
AFAIK, 'Tropical Islands' doesn't count as valid syntax!  You need to
isolate that string representation of a list before you can evaluate it.

Trusting your source.... eval simply evaluates a line of Python code. If,
for example, you were reading a parameter from an HTTP GET request and
executing it without validation, you could run into trouble if that variable
contained malicious code.  Think SQL injection style problems.


-Jeff

On 12/11/07, katie smith <iceboy127 at yahoo.com> wrote:
>
> I tried your suggestions and all that came up was the error
> Traceback (most recent call last):
>   File "C:\Python25\empire\Empire Strategy.pyw", line 1788, in <module>
>     NewMap1= eval (NewMap1, {}, {})
>   File "<string>", line 1
>     Tropical Islands
>                    ^
> SyntaxError: invalid syntax
>
> And what is this about trusting your source? The string is taken exactly
> from another part in the program so I know for sure it is correct if that is
> what that means.
>
> ------------------------------
> Never miss a thing. Make Yahoo your homepage.<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071211/1998c272/attachment.html>


More information about the Python-list mailing list