Eval and raw string ??

Peter Otten __peter__ at web.de
Wed Aug 22 12:13:08 EDT 2007


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



More information about the Python-list mailing list