file.read() doesn't read the whole file

Steve Holden steve at holdenweb.com
Mon Mar 23 14:51:30 CET 2009


Sreejith K wrote:
>> Try and write an example that shows the problem in fifteen lines or
>> less. Much easier for us to focus on the issue that way.
> 
> import os
> def read(length, offset):
> 	os.chdir('/mnt/gfs_local/')
> 	snap = open('mango.txt_snaps/snap1/0','r')
> 	snap.seek(offset)
> 	data = snap.read(length)
> 	print data
> 
> read(4096,0)
> 
> This code shows what actually happens inside the code I've written.
> This prints the 4096 bytes from the file '0' which is only 654 bytes.
> When we run the code we get the whole file. That's right. I also get
> it. But when this read() function becomes the file class read()
> function in fuse, the data printed is not the whole but only a few
> lines from the beginning.

This is confusing. I presume you to mean that when you make this
function a method of some class it stops operating correctly?

But I am not sure.

I am still struggling to understand your problem. Sorry,it's just a
language thing. If we take our time we will understand each other in the
end.

regards
 Steve
> I usually use less to read a file, when
> 'less'ing a file (whose size is less than 4096bytes) a call to read
> (0,4096) is made and data is returned. 'less' use this data returned
> by my fuse read() function to display its contents. But it was
> supposed to be the whole lines in the file like the example, but its
> not.... This is the problem I'm facing. Did I do something wrong here ?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
Holden Web LLC                 http://www.holdenweb.com/
Want to know? Come to PyCon - soon! http://us.pycon.org/




More information about the Python-list mailing list