readlines() doesn't read entire file

Peter Hansen peter at
Fri Jul 15 01:28:54 CEST 2005

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 
> syntax:
>         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 

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...


More information about the Python-list mailing list