<div>>>> a = '[1,2,3,4]'</div><div>>>> b = 'Tropical Islands'</div><div>>>> eval(a)</div><div>[1, 2, 3, 4]</div><div>>>> eval(b)</div><div>Traceback (most recent call last):
</div><div> File "<stdin>", line 1, in ?</div><div> File "<string>", line 1</div><div> Tropical Islands</div><div> ^</div><div>SyntaxError: unexpected EOF while parsing
</div><div>>>> </div><div><br> </div><div>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.
</div><div><br class="webkit-block-placeholder"></div><div>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.
</div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>-Jeff</div><div><br class="webkit-block-placeholder"></div><div><span class="gmail_quote">On 12/11/07, <b class="gmail_sendername">
katie smith</b> <<a href="mailto:iceboy127@yahoo.com">iceboy127@yahoo.com</a>> wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman, new york, times, serif;font-size:12pt">
<div style="font-size:12pt;font-family:times new roman, new york, times, serif">I tried your suggestions and all that came up was the error<br>Traceback (most recent call last):<br> File "C:\Python25\empire\Empire Strategy.pyw
", line 1788, in <module><br> NewMap1= eval (NewMap1, {}, {})<br> File "<string>", line 1<br> Tropical Islands<br> ^<br>SyntaxError: invalid syntax</div>
<div style="font-size:12pt;font-family:times new roman, new york, times, serif"> </div>
<div style="font-size:12pt;font-family:times new roman, new york, times, serif">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.
</div></div><span class="ad"><br>
<hr size="1">Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Make Yahoo your homepage.</a>
</span></div><br>--<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote>
</div><br>