[Pythonmac-SIG] file.read() after file.readline() problem

Jack Jansen jack@oratrix.nl
Fri, 05 Oct 2001 22:39:01 +0200


Folks,
I'm running into a problem that seems to have been around for some
time: I've now seen it in MacPython 2.1.1 and the (current CVS)
2.2a4+. If people with older Pythons could look at the following
scenario and tell me how far it goes back that would be helpful.

The problem is that if you have a file bigger than 4KB and you do
first a readline() and then a read() the read does not return all the
data: it returns only the first 4KB of the file (minus the bit that
has been read by the readline). To make matters more mysterious: after
a seek() the file behaves normally again.

A reasonable file to test this with is probably the installer log file
in the Python directory:
>>> fp = open('installer log file')
>>> d0 = fp.read()
>>> print 'real length', len(d0)
>>> fp = open('installer log file')
>>> d1 = fp.readline()
>>> d2 = fp.read()
>>> print len(d1), len(d2)
On my machine d2 does not contain all the data in the rest of the
file.

The following code does work correctly:
>>> fp = open('installer log file')
>>> fp.seek(0)
>>> d1 = fp.readline()
>>> d2 = fp.read()
>>> print len(d1), len(d2)

If you can help me find out around which time this bug was introduced
(and/or whether other people also see it, and it's not something
specific to my machine) that would help me a lot in tracing it.
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.cwi.nl/~jack        | ++++ see http://www.xs4all.nl/~tank/ ++++