Case sensitive file names

Peter Hansen peter at engcorp.com
Mon Feb 23 20:46:38 CET 2004


Thomas Philips wrote:
> 
> Thanks for all the help, everyone - the raw string solution seems the
> most practical, and it raises one final question: If I define a string
> x = "c:\python23\programs\test.txt"
> 
> How can I force open() or file() to treat it as a raw string. I expect
> to use a command of the form
> open(rx) or open(r"x") or open("r"+x)
> but none of these forms work.

You cannot.  You must specify the r at the time you define the string 
constant, because it is *during compilation* that the various escape
sequences are translated into ASCII control characters.  In your 
above example, by the time you've bound the name x to your string data,
you already have a TAB character where you don't want it. 

-Peter



More information about the Python-list mailing list