2011-11-12 188 views

回答

1

反斜杠转义是快速回答:

>>> '(+CMGL: 2,"REC READ","DD-Etopup",,"11/11/04,12:48:51+22" Hye! How\'s it going?)' 
'(+CMGL: 2,"REC READ","DD-Etopup",,"11/11/04,12:48:51+22" Hye! How\'s it going?)' 
>>> a = '(+CMGL: 2,"REC READ","DD-Etopup",,"11/11/04,12:48:51+22" Hye! How\'s it going?)' 
>>> a.split(',') 
['(+CMGL: 2', '"REC READ"', '"DD-Etopup"', '', '"11/11/04', '12:48:51+22" Hye! How\'s it going?)'] 
>>> a.split(',')[5] 
'12:48:51+22" Hye! How\'s it going?)' 
>>> len(a.split(',')[5]) 
34 
3

三重引号 - 这将允许嵌入的单和双引号没有转义字符

s = """(+CMGL: 2,"REC READ","DD-Etopup",,"11/11/04,12:48:51+22" Hye! How's it going?)""" 
+0

+1 legib。 ility。倒下反斜杠! –

+1

@JohnMachin:这个论点有一个小缺陷,如果你想要字面三倍单/双引号,你别无选择,只能逃避它们。 :) –

+0

反斜杠是最后的手段,因为它们是唯一可以逃脱的东西。我忘了提及三重引号,因为我只是将它们用于多行字符串。 –

相关问题