My simple script parse output screen and to a new file!

chuck amadi chuck.amadi at ntlworld.com
Thu Jun 10 08:14:21 CEST 2004


David Fisher wrote:

>chuck amadi <chuck.amadi at ntlworld.com> writes:
>  
>
>>fp = open("/home/chuck/pythonScript/testbox")
>> mbox = mailbox.UnixMailbox(fp, email.message_from_file)
>>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, you'll
>need to reinitalize it.  Just call:
>
>fp = open("/home/chuck/pythonScript/testbox")
>mbox = mailbox.UnixMailbox(fp, email.message_from_file)
>
>again before you use 'mbox' again.  Otherwise the file pointer is
>still pointing at the end of the file which is why you get nothing the
>second time.  Or alternately, just to be more confusing :), use:
>
>for mail in mailbox.UnixMailbox(open("/home/chuck/pythonScript/testbox"), \
>                                email.message_from_file):
>        print mail['Subject']
>        print mail.get_content_type()#text/plain
>        print mail.get_payload()
>
>Which does it all in one stroke.
>
>Oh, minor nitpick.  open(filename) is depredicated I believe.  The new
>prefered (for now :P) usage is file(filename).  Which makes sense
>since it returns a file object not an 'open' object
>
>  
>
>><{{{*>
>>    
>>
Cheers I thought I was going mad with that for loop .

Thanks





More information about the Python-list mailing list