Error with double backslash in Windows path in Python [duplicate]

If you are using a raw-string, then you do not escape backslashes:

f(r'E:\dir')

Of course, this problem (and many others like it) can be solved by simply using forwardslashes in paths:

f('E:/dir')

Leave a Comment