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

Steve Holden sholden at holdenweb.com
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
following:

D:\Steve\Projects\MailDB>python iotest.py 135101
File open at 0
read line Path:
atlpnn01.usenetserver.com!cyclone-atl1!newsfeeds-atl1.usenetserver.com!cyclo
ne2.usenetserver.com!europa.netcrusader.net!usenetserver.com!207.172.3.44!fe
ed2.news.rcn.net!rcn!nntp.abs.net!newsfeed.cwix.com!news-in.mts.net!news1.mt
s.net.POSTED!not-for-mail

File now at 219

Let's try another file:

D:\Steve\Projects\MailDB>python iotest.py 135102
File open at 0
read line From: sads <fsdf at d.com>

File now at
Traceback (most recent call last):
  File "iotest.py", 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!

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list