Convert backward slash to forward slash in python

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

    There is also os.path.normpath(), which converts backslashes and slashes depending on the local OS. Please see here for detailed usage info. You would use it this way:

    >>> string = r'C:/dummy_folder/a.txt'
    >>> os.path.normpath(string)
    'C:\dummy_folder\a.txt'
    

提交回复
热议问题