Triple quote escape ambiguity
>>> 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"
精彩评论