2010-07-30 216 views
0

嘿嘿一初學者這裏有點問題,我已經使用imaplib連接到IMAP服務器並獲取電子郵件,它返回如下:選擇元素的元組

[('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')'] 

我的問題是怎麼做的我只選擇主題元素(「Subject:Gmail is ...」)。

我嘗試了幾種組合,但尚未成功。

感謝您的幫助!

回答

0
email=[('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')'] 
    for subj in (subject for element in email for subject in element if subject.startswith("Subject")): 
     print subj 
""" Output 
    Subject: Gmail is different. Here's what you need to know. 
"""