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\"\\\"
The backslash can be used to make a following quote not terminate the string:
>>> r'\''
"\\'"
So r'foo\'
or r'\'
are unterminated literals.
Because you specifically asked for the reasoning behind this design decision, relevant aspects could be the following (although this is all based on speculation, of course):
So yes, there are probably important reasons why this way was chosen, even if you don't agree with these because you think that your specific use case is more important. It is however not, for the following reasons:
\
as a path separator, which is usually not necessary because Python supports /
as a path separator on Windows and because there's os.path.sep
.You can use '\\'
or "\\"
instead:
>>> print("\\")
\
Or if you're completely crazy, you can use raw string literal and combine them with normal literals just for the ending backslash or even use string slicing:
>>> r'C:\some\long\freakin\file\path''\\'
'C:\\some\\long\\freakin\\file\\path\\'
>>> r'C:\some\long\freakin\file\path\ '[:-1]
'C:\\some\\long\\freakin\\file\\path\\'
Or, in your particular case, you could just do:
paths = [ x.replace('/', '\\') for x in '''
/bla/foo/bar
/bla/foo/bloh
/buff
/
'''.strip().split()]
Which would save you some typing when adding more paths, as an additional bonus.