more on unescaping escapes

bvdp bob at
Mon Feb 23 20:31:20 EST 2009

Gabriel Genellina wrote:
> En Mon, 23 Feb 2009 22:46:34 -0200, bvdp <bob at> escribió:
>> Chris Rebert wrote:
>>> On Mon, Feb 23, 2009 at 4:26 PM, bvdp <bob at> wrote:
>>> [problem with Python and Windows paths using backslashes]
>>>  Is there any particular reason you can't just internally use regular
>>> forward-slashes for the paths? They work in Windows from Python in
>>> nearly all cases and you can easily interconvert using os.pathsep if
>>> you want the path to be pretty when you show it to (or get it from)
>>> the user or whatever.
>> Just because I never really thought too much about it :) I'm doing my 
>> work on a linux box and my user is on windows ... and he's used to 
>> using '\' ... but, you are absolutely right! Just use '/' on both 
>> systems and be done with it. Of course I still need to use \x20 for 
>> spaces, but that is easy.
> Why is that? "\x20" is exactly the same as " ". It's not like %20 in 
> URLs, that becomes a space only after decoding.
> py> '\x20' == ' '
> True
> py> '\x20' is ' '
> True
> (ok, the last line might show False, but being True means that both are 
> the very same object)

I need to use the \x20 because of my parser. I'm reading unquoted lines 
from a file. The file creater needs to use the form "foo\x20bar" without 
the quotes in the file so my parser can read it as a single token. 
Later, the string/token needs to be decoded with the \x20 converted to a 

So, in my file "foo bar" (no quotes) is read as 2 tokens; "foo\x20bar" 
is one.

So, it's not really a problem of what happens when you assign a string 
in the form "foo bar", rather how to convert the \x20 in a string to a 
space. I think the \\ just complicates the entire issue.

More information about the Python-list mailing list