What's the Scoop on \\ for Paths? (Win)

Tim Chase python.list at tim.thechases.com
Sun Jan 31 20:59:43 CET 2010


W. eWatson wrote:
> What am I missing here? Looks OK to me.
>  >>> abc.replace(r'\',r'z')
> 	
> SyntaxError: invalid syntax

A raw string can't end in a single backslash (something that 
occasionally annoys me, but I've learned to deal with it).

 >>> s=r'\'
   File "<stdin>", line 1
     s=r'\'
          ^
SyntaxError: EOL while scanning single-quoted string


My guess is that the parser sees the first call as

   abc.replace(
     r"r\'r"    <-- how your single-quoted is interpreted
     z'         <-- the leftovers that cause the syntax error
     )


-tkc






More information about the Python-list mailing list