My simple script parse output screen and to a new file!
Chuck Amadi
chuck at smtl.co.uk
Thu Jun 10 05:42:55 EDT 2004
Hi all got it to work using readlines() Thanks for your help folks.
learnt quite alot hopefully read my notes and the three Python books as I
bought some time to get to real use Python.
Thanks again Python List.
#!/usr/bin/env python
import sys
import os
import email
import mailbox
import StringIO
import struct
fp = file("/home/chuck/pythonScript/testbox")
mbox = mailbox.UnixMailbox(fp, email.message_from_file)
# list of body messages.
bodies = []
# mail is the file object
for mail in mbox:
print mail['Subject']
print mail.get_content_type()#text/plain
print mail.get_payload()
# If your going to use the UnixMailbox in two different loops,must
# need to reinitalize it.
fp = file("/home/chuck/pythonScript/testbox")
mb = mailbox.UnixMailbox(fp, email.message_from_file)
mailout = file("/home/chuck/pythonScript/SurveyResults.txt","a")
for line in fp.readlines():
mailout.write(line)
print "testbox file copied...to SurveyResults.txt cat to view"
# Now close the files
mailout.close
More information about the Python-list
mailing list