在字符串中,如果有反斜杠,我怎样才能将其更改为常规斜杠



我想在其中执行代码我正在从python中的用户那里获取路径现在在该路径中我想将''替换为'/'我用过re,但它是回溯告诉我我能做什么

import os,re
address = input("Enter Path You of the Folder Which Contains files")

check=re.compile('\')
if check.match(address):
for char in address:
if char == '\':
char.replace(char,'/')
print(address)

我使用操作系统的其他原因

address.replace('\\','/'(它将适用于字符串中的所有"\\"。

相关内容

最新更新