2011-11-12 150 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

反斜槓是最後的手段,因爲它們是唯一可以逃脫的東西。我忘了提及三重引號,因爲我只是將它們用於多行字符串。 –

相關問題