Script parse output screen but cant get desired output new file!.

Cameron Laird claird at lairds.com
Thu Jun 17 00:10:04 CEST 2004


In article <mailman.943.1087227855.6949.python-list at python.org>,
Chuck Amadi  <chuck at smtl.co.uk> wrote:
			.
			.
			.
>By the way list is there a better way than using the readlines() to
>parse the mail data into a file , because Im using
>email.message_from_file it returns 
>all the data i.e reads one entire line from the file , headers as well
>as just the desired body messages .
>
>fp = file("/home/chuck/pythonScript/testbox")
>mb = mailbox.UnixMailbox(fp,
>email.message_from_file)                          
>
>
>mailout = file("/home/chuck/pythonScript/SurveyResults.txt","w")
>for mail in fp.readlines():
>    mailout.write(mail)
>
>Something like this>
>
>for mail in mb:
>        body = mail.get_payload()
>	mailout.write(body) # write only the body messages to SurveyResults.txt
>
>Cheers if the is a better way I can't get my head round how I can print
>mail ( 
>only the body messages) to screen and the entire mail headers and body
>to the new file.
>
>Hi have any one got any suggstions to my script I can parse the email
>body messages to screen but I want the same desired effect to save to a
>new file.I have tried a few things to no effect.
			.
			.
			.
There's a lot going on in your message.  I *think* what you want
is the suggestion to replace
  for mail in fp.readlines():
      mailout.write(mail)
with
  mailout.write(fp.read())
-- 

Cameron Laird <claird at phaseit.net>
Business:  http://www.Phaseit.net



More information about the Python-list mailing list