r\'\\\'
in Python does not work as expected. Instead of returning a string with one character (a backslash) in it, it raises a SyntaxError. r\"\\\"
To address your root problem, you can use /
in paths on Windows in Python just fine.
The r''
and r""
syntax ( raw
) is primarily for working with regular expressions. It doesn't really get you anything in the case of working with paths like you are expecting, especially where the string ends with a \
.
Otherwise if you insist on using \
either use '\\'
or "\\"
, you have to escape the escape character which is \
; it isn't pretty, using /
or os.path.sep
is the best solution.