我有一个文件,其中包含多部分MIME文档中的tiff图像和文档xml。 我会从这个文件中提取图像。 我怎么能得到它?从MIME多部分文件中提取内容
我有这个代码,但它需要无限的时间来提取它,如果我有一个大文件(例如30Mb),所以这是无用的。
f=open("content_file.txt","rb")
msg = email.message_from_file(f)
j=0
image=False
for i in msg.walk():
if i.is_multipart():
#print "MULTIPART: "
continue
if i.get_content_maintype() == 'text':
j=j+1
continue
if i.get_content_maintype() == 'image':
image=True
j=j+1
pl = i.get_payload(decode=True)
localFile = open("map.out.tiff", 'wb')
localFile.write(pl)
continue
f.close()
if (image==False):
sys.exit(0);
非常感谢。
它适用于小文件......但我必须管理大文件(例如30mb),并且效果不佳。这需要很长时间,并且CPU总是被加载。 – michele 2010-10-09 08:48:01
有什么建议?谢谢。 – michele 2010-10-09 08:48:29