file's tell() method appears crazily broken (2.0)

Steve Holden sholden at
Sun Jan 27 10:02:00 EST 2002

Sorry if this is an old error, I couldn't find anything on SourceForge. I'd
really like to know if it's repeatable in other environments.

I cam across this when the rfc822 library failed reading a file containing a
newsgroup post. Some debugging led me to a really simple program which
exhibits the same error:

import sys
fp = open(sys.argv[1], "r")
print "File open at", fp.tell()
line = fp.readline()
print "read line", line
print "File now at", fp.tell()

Running this on Windows 98 using ActivePython 2.0, build 203, I see the

D:\Steve\Projects\MailDB>python 135101
File open at 0
read line Path:!cyclone-atl1!!cyclo!!!!fe!rcn!!!!!not-for-mail

File now at 219

Let's try another file:

D:\Steve\Projects\MailDB>python 135102
File open at 0
read line From: sads <fsdf at>

File now at
Traceback (most recent call last):
  File "", line 6, in ?
    print "File now at", fp.tell()
IOError: (0, 'Error')

What gives? Even stranger: I add a line to the failing file and the program
reports position -2. Trim some lines off and I see the 24 I'd expect. Cygwin
Python 2.1.1 seems to report correct file positions. Is this something that
got bugfixed between 2.0 and 2.1? I don't see it on the 2.1.1 list.

The file that fails appears to be 986 characters long, with no carriage
returns in it, just line feeds. Someone please tell me I'm not going crazy,
then I can make a sourceforge bug report!

Consulting, training, speaking:
Python Web Programming:

More information about the Python-list mailing list