readlines() doesn't read entire file

Jeremy jlconlin at
Fri Jul 15 01:46:32 CEST 2005

Peter Hansen wrote:
> Jeremy wrote:
>>I have a most aggravating problem.  I don't understand what is causing 
>>readlines() not to read all the lines in the file.  I have the following 
> ...
>>        self.xsdir = file(Datapath, 'r')        # File object
>>I can see all the lines in the list self.lines, but they are not all the 
>>lines in the file.  When I look at the file in Vim, I can see all the 
>>lines, but Python cannot.  Can someone help me with this one?
> What platform?  What version of Python?
> You're opening the file in "text" mode.  If you are on Windows and the 
> file actually contains a ^Z (byte 26) it is treated as EOF.  Is that the 
> problem?
> If not, have you tried cutting parts out of the file, to produce the 
> smallest file that still shows the problem?  At that point you will 
> likely resolve the issue on your own.  Also, does the same thing happen 
> if you use the interactive interpreter to read the file "manually"?
> These are all basic troubleshooting techniques you can use at any time 
> on any problem...
> -Peter
Well, now I have to make a humbling retraction.  I realized I wasn't 
reading the file I thought I was, but one similar to it.  Now that I am 
reading the correct file, I am getting all the lines I expected to.

More information about the Python-list mailing list