无法从字符文件中读取邮件正文

时间:2016-10-06 21:23:15

标签: python python-2.7 python-3.x

def MsgBody(count = Counter()):
    file = open('mbox.txt')
    count = 0
    for line in file: #Read every line in file
        if line.startswith('X-DSPAM-Probability:'): #MessageEnd
            words = line.split() # split words
            for words in file:
                if line.startswith('From'): #MessageStart
                    for i in words:
                        count += len(i)
    return count

我不知道为什么它会一直返回0,我认为它至少会返回一个数字。我的思维过程是使用for循环来读取文件中的每一行,如果该行以'X-DSPAM-Probability'开头,它将捕获并分割单词。使用另一个for循环来读取所有单词,一旦一行以'From'开头,它将捕获并使用另一个for循环来读取所有字符,然后它将添加到计数器。我不知道该怎么做。

0 个答案:

没有答案
相关问题