【问题标题】:Replace character "\" with "\\"?用“\\”替换字符“\”?
【发布时间】:2017-04-25 22:11:29
【问题描述】:

当我从 Windows 资源管理器中复制路径时,它将使用 "C:\Users" 表示法,而我实际上想要 "C:\\Users"。有什么功能可以代替我吗?

我已经发现可以使用codecs.decode(file_path, "unicode_escape") 解决相反的问题,但不确定这个方向。

【问题讨论】:

  • 粘贴到哪里?进入 Python 代码?在这种情况下,请使用原始字符串:r"<paste path here>"。否则,如果您将其粘贴到 input 或 UI 文本字段中,Python 将为您进行转义。

标签: python-3.x file replace decode codec


【解决方案1】:

tobias_k in a comment 所述,使用原始字符串:

在这种情况下,请使用原始字符串:r"<paste path here>"。否则,如果您将其粘贴到 input 或 UI 文本字段中,Python 将为您进行转义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    相关资源
    最近更新 更多