Python Convert Back Slashes to forward slashes

前端 未结 6 1916
滥情空心
滥情空心 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:30

    I recently found this and thought worth sharing:

    import os
    
    path = "C:\\temp\myFolder\example\\"
    
    newPath = path.replace(os.sep, '/')
    
    print newPath
    
    
    Output:<< C:/temp/myFolder/example/  >>
    

提交回复
热议问题