Is this a bug?
Fredrik Lundh
fredrik at pythonware.com
Sat May 12 05:14:44 EDT 2001
John Hopkins wrote:
> This just came up in one of the mailing lists I track. Python apparently
> requires that last '\' to be escaped, even though you're using "Raw".
>
> So myPath = r'c:\Windows\\' *should* work, though I haven't tried it.
it doesn't give you a syntax error, but it doesn't really do
what you expected:
>>> myPath = r'c:\Windows\\'
>>> print myPath
c:\Windows\\
for the full story on backslashes, see FAQ entry 6.29:
http://www.python.org/doc/FAQ.html#6.29
...
If you're trying to build Windows pathnames, note that all
Windows system calls accept forward slashes too:
f = open("/mydir/file.txt") # works fine!
If you're trying to build a pathname for a DOS command,
try e.g. one of
dir = r"\this\is\my\dos\dir" "\\"
dir = r"\this\is\my\dos\dir\ "[:-1]
dir = \\this\\is\\my\\dos\\dir\\
...
Cheers /F
More information about the Python-list
mailing list