473,322 Members | 1,347 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,322 software developers and data experts.

File.read() sometimes not reading everything

HI all,

I came across a strange behaviour with read method, and I'm not sure if
this is a filesystem problem or a misuse of this method.
I do the simple following thing :
f = open ('myFile','r')
content = f.read()
f.close()

When I use this lines really intensively sometimes, at random the content
is not the full content, it lacks some lines at the end.
When reading the file.read docstring I see that there can be some problems
with non-blocking file, but I suppose open() is by default creating a blocking
file.

Is the file line-buffered by default ? This could be a reason for this
early EOF, as I'm reading all the lines at once, and there is several
lines in the file ?

I'm at the moment trying to replace the previous read call by:
content = '\n'.join(f.readlines)
Not sure if this will work better, I'll say you.

Any other idea of this strange behaviour ? Can this be a problem with
filesystem also ?

Any ideas welcomed !

Boris
Jul 18 '05 #1
2 2179
Your file may contain an EOF character before the actual end
of file. You might want to try f=open('myFile','rb') to
open in binary mode, which would ignore EOF characters and
read the entire file.

-Larry
"Boris Boutillier" <bo**************@arteris.net> wrote in message
news:pa****************************@arteris.net...
HI all,

I came across a strange behaviour with read method, and I'm not sure if
this is a filesystem problem or a misuse of this method.
I do the simple following thing :
f = open ('myFile','r')
content = f.read()
f.close()

When I use this lines really intensively sometimes, at random the content
is not the full content, it lacks some lines at the end.
When reading the file.read docstring I see that there can be some problems
with non-blocking file, but I suppose open() is by default creating a blocking file.

Is the file line-buffered by default ? This could be a reason for this
early EOF, as I'm reading all the lines at once, and there is several
lines in the file ?

I'm at the moment trying to replace the previous read call by:
content = '\n'.join(f.readlines)
Not sure if this will work better, I'll say you.

Any other idea of this strange behaviour ? Can this be a problem with
filesystem also ?

Any ideas welcomed !

Boris

Jul 18 '05 #2
In article <pa****************************@arteris.net>,
"Boris Boutillier" <bo**************@arteris.net> wrote:
I came across a strange behaviour with read method, and I'm not sure if
this is a filesystem problem or a misuse of this method.
I do the simple following thing :
f = open ('myFile','r')
content = f.read()
f.close()

When I use this lines really intensively sometimes, at random the content
is not the full content, it lacks some lines at the end.
When reading the file.read docstring I see that there can be some problems
with non-blocking file, but I suppose open() is by default creating a blocking
file.

Is the file line-buffered by default ? This could be a reason for this
early EOF, as I'm reading all the lines at once, and there is several
lines in the file ?


No, a disk file will be block buffered. Not that it would matter.
Basically, the read method calculates the size of the file and tries
to fread(3) that amount. The only explanation I can think of (other
than an error somewhere) is a concurrent change to the file.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #3

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

Similar topics

8
by: Tom | last post by:
Hi, I have a log file and of course I want to add the new information to the end of that log file. Unfortunately I always delete the old information and only append the current info. Right now...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
12
by: A.M. | last post by:
Hi at all, how can I do to insert into a HTML page a file .txt stored in the same directory of the server where is the html file that must display the text file.txt? Thank you very much P.Pietro
2
by: John | last post by:
I am using the INPUT statement in VBA to read files off of CDROMs and DVDs. Normally everything works fine. However, sometimes portions of a file are unreadable, and this will lockup the Access...
18
by: junky_fellow | last post by:
What is the proper way of finding an end of file condition while reading a file ? How does feof() detects that end of file is reached ? Does this require support from OS ? Thanx in advance...
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
10
by: LuTHieR | last post by:
Hi, I'm reading a string of numbers from a file (using Borland C++ Builder 6), and I'm doing it like this: first I use FileRead to store all the data in the file to a char* variable (appropriately...
3
by: Newbieprogrammer | last post by:
Hello i need to make a function that would read these two lines 111 2222 3333 4444 5555 6666 7777 8888 222 3333 4444 notice that sometimes they are separated by one space and sometimes...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.