-1

I have a string which is a Windows path returned by another function. The function returns the path with a single backslash within it. Here I can't using raw string conversion to a variable. re.escape(path) does not work either. path.replace('\','\\') throws SyntaxError: unexpected character after line continuation character The function returns a path something like "D:\Data\201909\Foo\20190927c\Files" which gets coverted into "D:\\Data\ü909\\Foo\x8190927c\\Files"

path can be assumed as the variable containing the value returned by the function. Could you please suggest me a solution for this. Thanks Much !

Ritesh
  • 314
  • 6
  • 16

1 Answers1

-1

The below solution worked for me. path = r"{}" .format(path) where new variable path is the converted raw string.

Ritesh
  • 314
  • 6
  • 16
  • Raw strings only work with literal strings. `r"{}" == "{}"`. Update your question with a reproducible example showing *exactly* what is in your variable and what is wrong with it. – Mark Tolonen Aug 24 '20 at 16:20