python - Python:用斜杠替换反斜杠
问题描述
我有一条带有反斜杠的路径,path = "F:\Downloads\Images\Product\Samples"
但我想用slash替换反斜杠。我试过了,或者但我在扫描字符串文字时得到了 SyntaxError: EOL。怎么了?path.replace("\","/")
product_image.translate ({ord(c): "/" for c in "\"})
解决方案
path = "F:\Downloads\Images\Product\Samples"
path.replace("\\",r'/')
这应该这样做。
推荐阅读
- php - PHP删除for循环结果的最后一个逗号
- java - 如何在运行时和 dev-env 中从 jar 中复制文件夹的资源?
- c# - 在 Xamarin.Native(特别是 Android)的 C# 代码中定位相对布局的子视图
- c++ - 无法让 John Gruber 的 Web URL 正则表达式与 c++ std::regex 一起使用
- java - 安卓随机黑屏
- smartcard - 如何检查智能卡是否有效?
- python-3.x - Python 3 - 你如何重新创建你的 Pipfile?
- c# - 如何区分 Docker 中已挂载的卷和映像本机目录
- javascript - 访问 JavaScript 数组返回“未定义”
- php - 需要帮助设置谷歌日历 API