473,395 Members | 2,446 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,395 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
<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.
Katie,

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
something.

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.

Cheers,
Cliff
Dec 12 '07 #1
0 1143

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

Similar topics

6
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...
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
1
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:...
10
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=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.