readlines() doesn't read entire file
peter at engcorp.com
Fri Jul 15 01:28:54 CEST 2005
> 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
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