import imaplib, re
import os

while(True):
    conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
    conn.login("xxx", "xxxx")
    unreadCount = re.search("UNSEEN (\d+)", conn.status("INBOX", "(UNSEEN)")[1][0]).group(1)
    print unreadCount

    if unreadCount > 10:
      os.system('ls')

即使unreadCount小于10,它也会运行命令'ls'。为什么?

最佳答案

试试这个:

if int(unreadCount) > 10:
    os.system('ls')

09-13 07:20