Convert backward slash to forward slash in python

后端 未结 5 1156
说谎
说谎 2020-12-31 22:40

Hi I have read articles related converting backward to forward slashes. But sol was to use raw string.

But Problem in my case is :

I will get file path dyna

5条回答
  •  心在旅途
    2020-12-31 23:28

    Handling paths as a mere string could put you into troubles.; even more if the path you are handling is an user input or may vary in unpredictable ways.

    Different OS have different way to express the path of a given file, and every modern programming language has own methods to handle paths and file system references. Surely Python and Ruby have it:

    • Python: os.path
    • Ruby: File and FileUtils

    If you really need to handle strings:

    • Python: string.replace
    • Ruby : string.gsub

提交回复
热议问题