473,379 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

eval raising SyntaxError (was No Subject)

On Tue, 2007-12-11 at 16:55 -0800, katie smith 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
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.

First, please provide a useful subject heading when posting to the list.
It makes everyone's life easier when searching the archives.

Second, the example you provided in your last post was converting a
string of the form "[1,2,3,4,5]" to a list of integers. What is
happening here, is you are trying to convert a string of the form
"Tropical Islands" to... what?

I assume you are not getting the string you thought you would get. Eval
is acting as advertised. It is taking the line "Tropical Islands" and
trying to parse it as python code. If that's not what you wanted to do,
the question you should be asking is "why did I get the string "Tropical
Islands" instead of "[1,2,3,4,5]". You should not be asking "what is
eval doing wrong."

Before you were advised not to use eval unless you were sure of the
source of your inputs.

If the source of your input is "me," or "trusted operators" then you are
not sure of your inputs, because you might type something in thinking
that the focus was on a different window, or you might mistype

If the source of your inputs is a line you are extracting from another
python file, you are not sure of your inputs, because there could be an
error in your python file, or someone could add a line, so while
pulling, e.g., line 15 used to give you "[1,2,3,4,5]", that's now line
16, and line 15 gives you "Tropical Islands" instead, because somebody
thought there should be an extra blank line before the start of the code
or something.

If the source of your inputs is the output of another function, why is
it passing you a repr of a list instead of the list itself.

Almost NEVER use eval. If you find yourself using eval, make your next
task figuring out how not to use eval.

Dec 12 '07 #1
0 1142

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Chris Connett | last post by:
I have an interesting problem with eval(). ---Background Info--- The program I'm working on launches a separate process with a popen to do some highly specialized processing of input, then this...
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
by: =?ISO-8859-1?Q?Tor_Erik_S=F8nvisen?= | last post by:
Hi, A while ago I asked a question on the list about a simple eval function, capable of eval'ing simple python constructs (tuples, dicts, lists, strings, numbers etc) in a secure manner:...
by: TheSaint | last post by:
Hi, It seems to be strange that give me syntax error inside an eval statement. I'm looking at it carefully but I can't see any flaw. Here it's part of the code: for nn in stn_items: value=...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.