Newbie question: cannot read from file?

Cliff Wells LogiplexSoftware at earthlink.net
Tue Jan 14 19:43:10 EST 2003


On Tue, 2003-01-14 at 16:05, Nagy László wrote:
>   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+")

Since the data is a .bmp file, read it in binary mode:

f = file("Arwen.bmp","rb")


-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308






More information about the Python-list mailing list