raw strings under windows

Peter Hansen peter at engcorp.com
Sat Jun 14 05:20:09 EDT 2003


"Cecil H. Whitley" wrote:
> 
> When doing the following:
> 
> #!/usr/bin/env python
> 
> path = r"c:\python23\"
> 
> I get a syntax error, unexpected EOL with singlequoted string.  It was my
> (mis?) understanding that raw strings did not process escaped characters?
> Of course
> path = "c:\\python23\\"

Alternative that almost always works just fine as well:

path = "c:/python23/"

Try it... unless you're passing it to a command via os.system(), or 
doing direct string comparisons on paths without first using os.normpath()
you likely won't encounter a problem.  Windows internally allows forward
slash most of the time; in the DOS prompt it does not.

-PEter




More information about the Python-list mailing list