Newbie question: cannot read from file?

Nagy László nagylzs at freemail.hu
Tue Jan 14 19:05:20 EST 2003


  Hello Python Gurus!

I'm trying to read a file in 10000 byte blocks. The first read(10000) call
always reads 681 bytes. I'm not sure why 681. Any subsequent calls
to read(10000) read 0 bytes. If  I call f.tell(), that returns a wrong file
position (8192L) but after that I can read a few additional bytes in the
next read(10000) call. Then any subsequent calls to read(10000)
read 0 bytes, until I call tell() again (that will return 16384L). And so
goes on. I read the library reference and it tells that read(size) should
read at most "size" bytes from the file, or less if the read hits EOF.
This is all right, 0 is at most 10000 but I have a very bad feeling.
Did I missed something? Any pointer would help.

  Laci 1.0

This is "dir":

2003.01.15.  00:47    <DIR>          .
2003.01.15.  00:47    <DIR>          ..
2003.01.13.  10:50         2 359 350 Arwen.bmp
2003.01.14.  22:37                69 Test.txt



 >>> f = file("Arwen.bmp","r+")
 >>>data = f.read(10000)
 >>>len(data) # Why just 681?
681
 >>>data = f.read(10000)
 >>>len(data) # Why always zero?
0
 >>>data = f.read(10000)
 >>>len(data)
0
 >>>data = f.read(10000)
 >>>len(data)
0
 >>>f.tell() # Isn't it false?
8192L
 >>>data = f.read(10000)
 >>>len(data)
1153
...







More information about the Python-list mailing list