我正在处理来自我的thunderbird imap目录的大型(120mb)文本文件,并尝试使用mbox和正则表达式从头信息中提取信息。该进程运行一段时间,直到我最终得到一个异常:“TypeError:预期的字符串或缓冲区”。用Python处理文本文件时的预期字符串或缓冲区
异常引用该代码的第五行:
PAT_EMAIL = re.compile(r"[0-9A-Za-z._-]+\@[0-9A-Za-z._-]+")
temp_list = []
mymbox = mbox("data.txt")
for email in mymbox.values():
from_address = PAT_EMAIL.findall(email["from"])
to_address = PAT_EMAIL.findall(email["to"])
for item in from_address:
temp_list.append(item) #items are added to a temporary list where they are sorted then written to file
我已经在其他(较小)文件运行的代码,所以我猜这个问题是我的文件。该文件似乎只是一堆文本。有人能指出我的写作方向来调试吗?
在失败的迭代中检查'type(email [“from”])'''。 – 2013-02-26 03:51:08
你可以发布你的'findall'方法的代码吗? – eazar001 2013-02-26 04:12:46
增加了findall方法来发布。 – spatialaustin 2013-02-26 05:46:03