首页 > 解决方案 > Python:用斜杠替换反斜杠

问题描述

我有一条带有反斜杠的路径,path = "F:\Downloads\Images\Product\Samples"但我想用slash替换反斜杠。我试过了,或者但我在扫描字符串文字时得到了 SyntaxError: EOL。怎么了?path.replace("\","/")product_image.translate ({ord(c): "/" for c in "\"})

标签: pythonsyntax-errorspecial-characters

解决方案


path = "F:\Downloads\Images\Product\Samples"
path.replace("\\",r'/')

这应该这样做。


推荐阅读