file read : feature or bug ?
Jeff Epler
jepler at unpythonic.net
Tue Apr 15 15:48:11 EDT 2003
On Tue, Apr 15, 2003 at 06:51:47PM +0200, Asbuilt Easynet wrote:
> But is there a workaround ?
Yes, kinda.
> > When you're using text files, seek will not operate as you expect. The
^^^^
If you open your file in binary (f = open(filename, "rb")) you'll be
able to use seek() in the way you expect. *BUT* "newline translation"
is also not performed. This means that if you wrote a text file on
Windows (opened in "w" mode) you will see the byte sequence '\r\n' where
you wrote a newline before. On platforms with even more bizarre ideas
of what makes a "text file", you could get even stranger things, but
nobody uses those anymore, anyway. Remember, "all the world's a vax".
I don't exactly remember how your program worked, but you can also use
the advice to only use a value returned from the tell() method when
seeking in a file. This is actually guaranteed (by the C language
standard) to work and do what you'd expect.
Jeff
More information about the Python-list
mailing list