473,951 Members | 3,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1259
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...@g mail.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
61262
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
16
2201
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 caused the application to go boom. Sometimes the page will compile and run using F5 and others not. So I do the web search tango looking around the blogs and the tuts and determine I should go into Temporary ASP.NET Files and delete the directory...
1
2823
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 following is the code,, #include <iostream> #include <string> #include <stdio.h> #include <stdlib.h> #include <ctime // For time()
2
1560
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 it while it is open. Neither process sees any anomaly or error. Do the NT file systems support this feature (which I think is standard for POSIX systems)?
0
10173
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9994
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11198
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6357
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4555
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.