seek() tell()

Jeff Epler jepler at unpythonic.net
Wed Feb 5 09:13:30 EST 2003


You're probably using windows and opening files in "text mode".
According to the C standard (as I recall it) the value returned from
ftell() is an opaque cookie when a file is opened in text mode.  It is a
byte offset when a file is opened in binary mode.

On Windows, the number returned by ftell() will be the number you would
have gotten if you had treated the file as binary and written \n as \r\n
(so 1 is added for each \n, essentially).  However, it was the intent of
the folks who wrote the standard to accomodate systems where "text
files" are files with fixed-length records, one record per line.  On
those systems, the number returned might turn out to be (for example)
a 25:7 bit split (line number:line position, giving files up to 32M
lines long with up to 127 chars per line)

Jeff





More information about the Python-list mailing list