Mailbox, tell and read

Gordon McMillan Gordon.McMillan at
Wed Jun 30 14:14:42 EDT 1999

From: "Gordon McMillan" <gmcm at>

Paul Prescod writes:

> The mailbox message objects simulate a file interface by seeking
> through a mailbox. A read() returns the entire message. It does this
> by seeking to the start, reading to the message end, and returning
> the data. The problem is that message offsets are derived by
> file.tell() which I presume is in terms of bytes. But then it does a
> read() based on the offsets and read() is in terms of characters. 
> These don't match up on Windows because of CR/LF pairs. I think that
> the right fix is to never use tell() and instead keep track of the
> location by counting characters. Does that make sense? -- 

How 'bout opening in binary, and munging line endings yourself just 
before returning the message? If you can't use tell(), you can't 
trust seek(), either.

- Gordon

More information about the Python-list mailing list