python - 三引号转义歧义

标签 python string

>>> sample7 = """including 'quote1' "quote2" and 'quote3" """
>>> sample7
'including \'quote1\' "quote2" and \'quote3" '
>>> print sample7
including 'quote1' "quote2" and 'quote3" 

在这里,字符串 sample7 中的引号被三重引号正确转义。但是,

>>> sample4 = """c:\ntext\text\file.rtf"""
>>> sample4
'c:\ntext\text\x0cile.rtf'
>>> print sample4
c:
text    extile.rtf

sample4 中的反斜杠没有被三重引号正确转义。这是为什么?应该做什么来自动逃避。类似的东西,

String file = @"c:\ntext\text\file.rtf";

在 C# 中。

附言。另外,我是如何得到 \x0cile.rtf 而不是 \file.rtf 的?

谢谢。

最佳答案

Python 正在评估\f 只使用原始字符串

r"c:\ntext\text\file.rtf"

关于python - 三引号转义歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5234081/

相关文章:

python - 为 python 数据类中的字段定义约束

r - R中大写和小写字符之间的字符串拆分?

python - pandas 根据条件将数据转换为多步时间序列

Python、WSGI、多处理和共享数据

Python新手生成随机字符串

c++ - 如何将字符串混淆成 C++ 二进制文件?

c - 使用C从文本文件中删除多个字符

C++ STD find_last_of 不工作?

python - 如何在 pytest 中使用 monkeypatch 或 mock 删除库?

python - 使用 python 队列进行 Django Rest Framework 测试