-1

I have a variable containing folderpath in format C:/folder/folder. I need to covert it into C:\folder\folder. I tried this script: folder_path = folder_path.replace("/", "\"), but the last "\" is being interpeted by something other than a string containing character: \

How do I tell python I literarily whant only charater \ in a string?

Heikki
  • 341
  • 2
  • 18

2 Answers2

1

You can use either an escape sequence '\\' like so:

path = 'C:\\something\\another'

Or you can use "raw strings":

path = r'C:\something\another'

The documentation about raw strings and escape patterns is listed here

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62
1

you need to use two \ instead of one \ since \ is escape character

a = "C:/folder/folder"
b = a.replace("/", "\\")