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

Sreejith K sreejithemk at gmail.com
Fri Mar 20 02:36:46 EDT 2009


Hi,

>>> snapdir = './mango.txt_snaps'
>>> snap_cnt = 1
>>> block = 0
>>> import os
>>> os.chdir('/mnt/gfs_local')
>>> snap = open(snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)),'r')
>>> snap.read()
'dfdfdgagdfgdf\ngdgfadgagadg\nagafg\n\nfs\nf\nsadf\n\nsdfsdfsadf\n'
>>> snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block))
'./mango.txt_snaps/snap1/0'

The above code works fine and it reads the whole file till EOF. But
when this method is used in a different scenario the file is not read
completely. I'll post the code that read only some part of the file...

self.snap = open(self.snapdir + '/snap%d/%d' % (self.snap_cnt,
block),'r') ## opens /mnt/gfs_local/mango.txt_snaps/snap1/0
self.snap.seek(off%4096) ## seeks to 0 in this case
bend = 4096-(off%4096) ## 4096 in this case
if length-bend <= 0:    ## true in this case as length is 4096
	tf.writelines("returned \n")
	data = self.snap.read(length)
	self.snap.close()
	break

the output data is supposed to read the whole fie but it only reads a
part of it. Why is it encountering an early EOF ?



More information about the Python-list mailing list