Windows file paths, again

Jerry Hill malaclypse2 at
Thu Oct 22 00:18:31 CEST 2009

On Wed, Oct 21, 2009 at 5:40 PM, Dan Guido <dguido at> wrote:
> This doesn't give me quite the results I expected, so I'll have to
> take a closer look at my project as a whole tomorrow. The test cases
> clearly show the need for all the fancy parsing I'm doing on the path
> though.

To get back to what I think was your original question, there is an
easy way to take a string with control characters and turn it back
into a string with the control characters escaped, which could replace
your escape_dict and raw() function in

>>> s = 'Foo\t\n\n\x12Bar'
>>> print s

>>> r = s.encode('string-escape')
>>> print r

(Python 2.6.1 on windows XP)

More generally, it sounds like you have some bad data in either the
registry, or your ini file.  You shouldn't have control characters in
there (unless you really have directories with control characters in
their names).  If you have control over how those values are written,
you should probably fix the bad data at the source instead of fixing
it as you pull it back in.


More information about the Python-list mailing list