472,142 Members | 1,037 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 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 1979
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 leo001 | last post: by

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.