469,588 Members | 2,760 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

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 1845
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Reply Via Newsgroup | last post: by
11 posts views Thread by sneill | last post: by
reply views Thread by Michelle Keys | last post: by
18 posts views Thread by Joe Fallon | last post: by
24 posts views Thread by Larry | last post: by
15 posts views Thread by manstey | last post: by
3 posts views Thread by Pauljh | last post: by
reply views Thread by J. Clifford Dyer | last post: by
16 posts views Thread by Fett | last post: by
reply views Thread by Jean-Paul Calderone | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.