error using mailbox

Mark Rowe bdash at gmx.net
Wed May 22 02:15:39 EDT 2002


David Bear wrote:

>Have python 2.1 installed on caldera open linux -- python 1.5 is also 
>installed but all my symlink point to 2.1.  I'm attempting to using the 
>mailbox module and am getting the following:
>
>Traceback (most recent call last):
>  File "./unixmail.py", line 8, in ?
>    msg = mb.next()
>  File "/usr/local/lib/python2.1/mailbox.py", line 19, in next
>    self.fp.seek(self.seekp)
>AttributeError: seek
>
>my code is straight from the psl 2.0 book by oreilly..
>
>#!/usr/local/bin/python
># psl2.0 p 156
>import mailbox
>
>mb = mailbox.UnixMailbox("syslog/npcenter")
>
>while 1:
>        msg = mb.next()
>        if not msg:
>                break
>        for k, v in msg.items():
>                print k, "=", v
>        body = msg.fp.read()
>        print body
>
>Aside from the book is wrong, mailbox takes a file name rather than a file 
>object, the code is exact.  Any reason I'm getting the attribute error?
>
>  
>
Hello,

The UnixMailbox constructor expects an open file object as its 
parameter, so you should call it like

mb = mailbox.UnixMailbox(open("syslog/npcenter"))


Mark Rowe







More information about the Python-list mailing list