Skip to main content
added 7 characters in body
Source Link
UncleZeiv
  • 18.6k
  • 7
  • 53
  • 77

There are a number of problems:

  • The syntax of your path.replace line is incorrect. \ is an escape character and as such it needs to be escaped by prepending another \.
  • path.replace works the other way around: first the thing you want to substitute, then the thing you want to substitute it with.
  • Your string doesn't contain all of the backslashes anymore, because they have been interpreted as ... escape characters. You need to create a "raw" string.

Putting it all together:

path = r"/Users/xx/datasets/yyy/DefinedTS\Training\00000"
path = path.replace("\\", "/")
print(path)

There are a number of problems:

  • The syntax of your path.replace line is incorrect. \ is an escape character and as such it needs to be escaped by prepending another \.
  • path.replace works the other way around: first the thing you want to substitute, then the thing you want to substitute it with.
  • Your string doesn't contain all of the backslashes anymore, because they have been interpreted as ... escape characters. You need to create a "raw" string.

Putting it all together:

path = r"/Users/xx/datasets/yyy/DefinedTS\Training\00000"
path.replace("\\", "/")
print(path)

There are a number of problems:

  • The syntax of your path.replace line is incorrect. \ is an escape character and as such it needs to be escaped by prepending another \.
  • path.replace works the other way around: first the thing you want to substitute, then the thing you want to substitute it with.
  • Your string doesn't contain all of the backslashes anymore, because they have been interpreted as ... escape characters. You need to create a "raw" string.

Putting it all together:

path = r"/Users/xx/datasets/yyy/DefinedTS\Training\00000"
path = path.replace("\\", "/")
print(path)
Source Link
UncleZeiv
  • 18.6k
  • 7
  • 53
  • 77

There are a number of problems:

  • The syntax of your path.replace line is incorrect. \ is an escape character and as such it needs to be escaped by prepending another \.
  • path.replace works the other way around: first the thing you want to substitute, then the thing you want to substitute it with.
  • Your string doesn't contain all of the backslashes anymore, because they have been interpreted as ... escape characters. You need to create a "raw" string.

Putting it all together:

path = r"/Users/xx/datasets/yyy/DefinedTS\Training\00000"
path.replace("\\", "/")
print(path)