开发者

Triple quote escape ambiguity

开发者 https://www.devze.com 2023-02-15 08:10 出处:网络
>>> sample7 = \"\"\"including \'quote1\' \"quote2\" and \'quote3\" \"\"\" >>> sample7
>>> sample7 = """including 'quote1' "quote2" and 'quote3" """
>>> sample7
'including \'quo开发者_如何学编程te1\' "quote2" and \'quote3" '
>>> print sample7
including 'quote1' "quote2" and 'quote3" 

Here, the quotes inside the string sample7 was properly escaped by the triple quotes. 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. Why is that? What should be done to escape that automatically. Something like,

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

in C#.

PS. Also, how did I get \x0cile.rtf instead of \file.rtf?

Thanks.


Python is evaluating \f Just use raw strings

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

精彩评论

暂无评论...
验证码 换一张
取 消