简体   繁体   English

三引号转义歧义

[英]Triple quote escape ambiguity

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

Here, the quotes inside the string sample7 was properly escaped by the triple quotes. 在这里,字符串sample7内的引号被三重引号正确地转义了。 But, 但,

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

The backslashes in sample4 were not properly escaped by the triple quote. sample4中, sample4中的反斜杠没有正确地转义。 Why is that? 这是为什么? What should be done to escape that automatically. 应该采取什么措施才能自动转义。 Something like, 就像是,

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

in C#. 在C#中。

PS. PS。 Also, how did I get \\x0cile.rtf instead of \\file.rtf ? 另外,我如何获得\\x0cile.rtf而不是\\file.rtf

Thanks. 谢谢。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM