msg.walk()

pythonhda pythonhda at yahoo.com.replacepythonwithlinux
Sun Jun 27 15:42:22 CEST 2004


On Sat, 26 Jun 2004 15:30:04 +0100
Samuel Wright <lykoszine at gmail.com> wrote:

> Hi Guys
> 
> Using Python 2.3 here, trying to parse a MBOX email file using the
> code below:
> 
> [...]
> def msgfactory(fp):
>     try:
>         return email.message_from_file(fp)
>     except email.Errors.MessageParseError:
>         # Don't return None since that will
> 	# stop the mailbox iterator
> 	return ''
>

Notice the return ''
 
> 
> def main():
>     fp = open(mailboxfile, 'r')
>     mbox = mailbox.UnixMailbox(fp, msgfactory)
>     for msg in mbox:
>         print msg
>         for part in msg.walk():
>            print part
> [...]

You have to do a test for an empty string in your main method (like the docs say).



More information about the Python-list mailing list