473,396 Members | 1,990 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,396 software developers and data experts.

Eval and raw string ??

Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tklll\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
eval("r'C:\tklll\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark

Aug 22 '07 #1
4 2071
On Aug 22, 11:06 am, Mark <cree...@gmail.comwrote:
Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tklll\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
eval("r'C:\tklll\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark
The r'' format is purely for the interpreter; eval wouldn't know the
difference.

Your problem is that eval and exec evaluate source. You're trying to
do execfile().

Fred

Aug 22 '07 #2
Mark wrote:
Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tklll\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
eval("r'C:\tklll\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string
The string you are passing to eval already contains that newline. Use a raw
string instead:
>>eval(r"r'C:\tklll\ndfd\bll'")
'C:\\tklll\\ndfd\\bll'

Peter
Aug 22 '07 #3
On Aug 22, 11:06 am, Mark <cree...@gmail.comwrote:
Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tklll\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
eval("r'C:\tklll\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

Thanks in advance,
Mark
This is not a raw string: "r'\tsomething in quotes'". It is a string
starting with an "r", a "'", a tab, and and "s".

This is a raw string: r'\tsomething in quotes'. It is a string
starting with a "\", a "t" and an "s".

Notice that the \t and \n in c:\tkllll\ndfd\bll were treated like tab
and newline? Try eval(r'c:\tkllll\ndfd\bll')

(You will get a different error now, but it wont be a raw string
problem.)

-- Paul
Aug 22 '07 #4
Mark <cr*****@gmail.comwrote:
Eval() doesn't seem to recognize the r'string' format. Is there a way
around this.
Example:
If I input: ---------eval("r'C:\tklll\ndfd\bll'")
I get the output:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
eval("r'C:\tklll\ndfd\bll'")
File "<string>", line 1
r'C: klll
^
SyntaxError: EOL while scanning single-quoted string

The same principle applies for exec.

The \n is being converted to a newline before the string is passed to eval.

Try eval(r"r'C:\tklll\ndfd\bll'")

-M-
Aug 22 '07 #5

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

Similar topics

7
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed...
11
by: sneill | last post by:
I have read a number of posts on the use of eval() in Javascript, and I agree that its use is questionable. But it does beg the following question: "How arbitrary does a string need to be before...
0
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
24
by: Larry | last post by:
Hi there: I have seen numerous postings about eval() and its evils on this forum. However, one of our developers is using it in the following way, which seems like a great use of it. Page...
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
3
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do...
0
by: J. Clifford Dyer | last post by:
On Tue, 2007-12-11 at 16:55 -0800, katie smith wrote: Katie, First, please provide a useful subject heading when posting to the list. It makes everyone's life easier when searching the...
16
by: Fett | last post by:
I am creating a program that requires some data that must be kept up to date. What I plan is to put this data up on a web-site then have the program periodically pull the data off the web-site. ...
0
by: Jean-Paul Calderone | last post by:
On Thu, 28 Aug 2008 14:51:57 -0700 (PDT), Fett <fettmanchu@gmail.comwrote: eval and exec are the same. Don't use either with strings from a web page. Try using a simple format for you data, such...
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...
0
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
0
BarryA
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.