Convert backward slash to forward slash in python

后端 未结 5 1125
说谎
说谎 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:16

    Don't do this. Just use os.path and let it handle everything. You should not explicitly set the forward or backward slashes.

    >>> var=r'C:\dummy_folder\a.txt'
    >>> var.replace('\\', '/')
    'C:/dummy_folder/a.txt'
    

    But again, don't. Just use os.path and be happy!

提交回复
热议问题