Is there a not-ugly way to replace os.sep with '/'? [duplicate]

So I have following problem:

"L:\GDrive\test\img.png".replace(os.sep, '/')

returning

"L:/GDrive\test/img.png"

Is there a way to replace all \ characters without manually going over all possible special symbols like \t? Need to preserve t of course.


Solution 1:

try use "r" before the path:

r"L:\GDrive\test\img.png".replace(os.sep, '/')

output:

'L:/GDrive/test/img.png'