Python Convert Back Slashes to forward slashes

前端 未结 6 1881
滥情空心
滥情空心 2020-12-15 16:11

I am working in python and I need to convert this:

C:\\folderA\\folderB to C:/folderA/folderB

I have three approaches:

dir = s.replace(\'\\\\         


        
6条回答
  •  囚心锁ツ
    2020-12-15 16:40

    To define the path's variable you have to add r initially, then add the replace statement .replace('\\', '/') at the end.

    for example:

    In>>  path2 = r'C:\Users\User\Documents\Project\Em2Lph\'.replace('\\', '/')
    In>>  path2 
    Out>> 'C:/Users/User/Documents/Project/Em2Lph/'
    

    This solution requires no additional libraries

提交回复
热议问题