file reading anomaly
gerard.blais at gmail.com
Fri Jul 6 20:20:06 CEST 2007
The PC seems to not be a factor (same problem exist on two PCs).
The entire script does some computation and writes depstats.txt.
The code snippet below attempts to read depstats.txt and write another
file. When the code below is run stand-alone, it succeeds. When run
in-line as part of the program that wrote depstats.txt, there are
three possible outcomes:
it stops reading after 4096 bytes (not counting \r's); no error
it stops reading after 8192 bytes (not counting \r's); no error
or it succeeds.
The first two are much more likely.
Trying buffersize parameters of -1, 0, 1, 1000, 8192, 16384 in the
open call for m all had no apparent effect.
Any ideas what could possibly be wrong earlier to cause this?
m = open("depstats.txt", "r", 20000)
n = open("newds.txt", "w")
linesout = 0
bytes = 0
for line in m:
bytes += len(line)
print len(line), len(line.split()), bytes
t = line.split()
if len(t) < 13:
print "not enough fields, only", len(t)
while len(t) < 43:
t = [str(x) for x in t]
print >> n, " ".join(t)
linesout += 1
print "linesout", linesout
On Jul 6, 12:48 pm, Gerry <gerard.bl... at gmail.com> wrote:
> Python 2.5, Windows XP.
> I have a 48-line text file written by a Windows python script,
> I try to read it as follows:
> f = open ("depstats.txt", "r", 0)
> for index, line in enumerate(f):
> print index, len(line), len(line.split())
> On one PC, this runs without any problem.
> On another, it appears to succeed (no run-time errors) but does not
> read all the lines. If I print the lines and sum of the line lengths
> so far inside the loop, the program can be seen to have only read the
> first N bytes, where N is either 4096, or 8192.
> Any ideas?
More information about the Python-list