Python windows path slash [duplicate]
Python interprets a \t
in a string as a tab character; hence, "D:\testfolder"
will print out with a tab between the :
and the e
, as you noticed. If you want an actual backslash, you need to escape the backslash by entering it as \\
:
>>> x = "D:\\testfolder"
>>> print x
D:\testfolder
However, for cross-platform compatibility, you should probably use os.path.join
. I think that Python on Windows will automatically handle forward slashes (/
) properly, too.