I am trying to convert Windows file path to Unix using os.path.normpath
. I am getting unexpected characters in file path.
import os
path1 = 'C:\Users\abcd\dir1'
path2 = os.path.normpath(path1)
path2
I want to replace "\" by "/". But output is 'C:\\Users\x07bcd\\dir1'
. I am wondering how x07` comes in the picture and how to get rid of it.
Alternatively, I tried regex to replace "\" by "/".
Desired output is: 'C:/Users/abcd/dir1'
I tried using answer of Python how to replace backslash with re.sub() but could not get it to work. If I want to use it, can someone suggest how to do it?
path3 = re.sub(path1 +"\\" "//")
But there is error. I am new to python, so could not figure out proper syntax.