1
>>> 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";
in C#。
PS。另外,我怎麼得到\x0cile.rtf
而不是\file.rtf
?
謝謝。
@mirabilos我找不到它不是由原始字符串忽略任何轉義序列。唯一的例外是原始字符串不能以奇數個斜線結束。例如。 'print r'test \\\\「'yield test \\\\但'print r'test \\'」'給出錯誤。 – Jim 2015-06-17 11:10:30
@Jim對,正好。這對於自動轉義來說確實是一件有問題的事情。比較shell,它非常容易:前綴''',後綴''',用'''''替換裏面的所有''',完成。 – mirabilos 2015-06-17 12:31:17