-3

I have a path with backslashes like path = "F:\Downloads\Images\Product\Samples" but i want to replace backslash with slash. I tried path.replace("\","/") or product_image.translate ({ord(c): "/" for c in "\"}) but i get SyntaxError: EOL while scanning string literal. What is wrong?

  • https://stackoverflow.com/questions/3561691/python-syntaxerror-eol-while-scanning-string-literal found this now, it is a duplicate – ombk Nov 29 '20 at 09:50

2 Answers2

2
path = "F:\Downloads\Images\Product\Samples"
path.replace("\\",r'/')

this should do it.

ombk
  • 2,036
  • 1
  • 4
  • 16
0

You have to escape special characters by \. Try:

path.replace("\\","\/")