Python2.2 + mailbox. Bug????
Noam Raphael
noamr at correctme.users.sourcephorge.net
Fri May 21 12:18:40 EDT 2004
hector wrote:
> Hi
>
> This is my program:
>
> #!/usr/bin/python
> import sys
> from mailbox import PortableUnixMailbox
> tmp = sys.stdin
> mbox = PortableUnixMailbox(tmp)
> mbox.next()
> ...
> ...
>
> When I execute: "./program.py < mboxfile.txt", there's no problem
>
> But, if I execute: "cat mboxfile.txt | program.py" ... too bad!
>
> the error:
>
> Traceback (most recent call last):
> File "./prueba.py", line 8, in ?
> mbox.next()
> File "/usr/lib/python2.2/mailbox.py", line 23, in next
> self.fp.seek(self.seekp)
> IOError: [Errno 29] Illegal seek
>
> Why????? Thanks ALL!!
Hello,
I assume that when you write "./program.py < mboxfile.txt", Python knows
that sys.stdin is a regular file, so it can do seek on it (for example,
go back to its beginning). When you write "cat mboxfile.txt |
program.py", the program cat outputs the file mboxfile.txt into
sys.stdin byte by byte, so you can't do seek on it.
Bye,
Noam
More information about the Python-list
mailing list