Windows file paths, again

Anthony Tolle anthony.tolle at
Wed Oct 21 21:50:02 CEST 2009

On Oct 21, 3:20 pm, Dan Guido <dgu... at> wrote:
> Hi Diez,
> The source of the string literals is ConfigParser, so I can't just
> mark them with an 'r'.
> config = ConfigParser.RawConfigParser()
> crazyfilepath = config.get(name, "ImagePath")
> normalfilepath = normalize_path(crazyfilepath)
> The ultimate origin of the strings is the _winreg function. Here I
> also can't mark them with an 'r'.
> regkey = OpenKey(HKEY_LOCAL_MACHINE,
> "SYSTEM\\CurrentControlSet\\Services\\" + name)
> crazyimagepath = QueryValueEx(regkey, "ImagePath")[0]
> CloseKey(key)
> --
> Dan Guido

I just did a quick test using Python 2.5.1 with the following script
on Windows:

# start of
import ConfigParser
config = ConfigParser.RawConfigParser()"cfg.ini")
x = config.get("foo", "bar")
print x
print repr(x)
from _winreg import *
regkey = OpenKey(HKEY_LOCAL_MACHINE,
x = QueryValueEx(regkey, "ImagePath")[0]
print x
print repr(x)
# end of

Here is the contesnts of cfg.ini:


Here is the output of the script:


In either case, I don't see the functions returning strings that
requires special handling.  The backslashes are properly escaped in
the repr of both strings.

Something else must be going on if the strings are getting messed up
along the way.

More information about the Python-list mailing list