473,382 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

file reading anomaly

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())
f.close()

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?

Thanks,

Gerry

Jul 6 '07 #1
2 1234
Update:

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
messages
it stops reading after 8192 bytes (not counting \r's); no error
messages
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)
print t
sys.exit()
while len(t) < 43:
t.append(0)
t.append("F2")
t = [str(x) for x in t]
print >n, " ".join(t)
linesout += 1

print "linesout", linesout

m.close()
n.close()

On Jul 6, 12:48 pm, Gerry <gerard.bl...@gmail.comwrote:
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())
f.close()

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?

Thanks,

Gerry

Jul 6 '07 #2
Final update: problem solved. In the big script, the snippet was
reading depstats.txt which hadn't been closed.

Sorry for all the bother.

Gerry

Jul 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
16
by: clintonG | last post by:
At design-time the application just decides to go boom claiming it can't find a dll. This occurs sporadically. Doing a simple edit in the HTML for example and then viewing the application has...
1
by: mai | last post by:
Hi everyone, i'm trying to exhibit FIFO anomaly(page replacement algorithm),, I searched over 2000 random strings but i couldnt find any anomaly,, am i I doing it right?,, Please help,,,The...
2
by: aaron.watters | last post by:
Hi. I'm writing an archival system which I'd like to be portable to Windows. The system relies on the property of Unix which allows a process to keep a file open even if another process renames...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.