Behaviour of filehandle.readlines() for images on Windows

Jorge Godoy godoy at metalab.unc.edu
Tue Oct 14 16:35:33 EDT 2003


Alex Martelli <aleax at aleax.it> writes:

> Assuming it's the latter issue, which seems most likely, open the
> file with option 'rb' for "reading binary".  E.g.,
>
>     myfile = file('foo.jpg', 'rb')
>
> it's doubtful that you want to use readlines on a binary file, though.

That's what I was looking for but didn't remember that I could open it
in a binary way. :-\ I was looking for something like a rawread() in
the docs, believe it or not. We tend do look for answers the hardest
way :-)

With regards to using readlines, I'm using it to get some information
that is readable in text format and that happens to be stored on a PNG
image. I was thinking about using something to read the 'n' bytes I
need but the binary flag solved my problem. 


Thank you very much. 

-- 
Godoy.     <godoy at metalab.unc.edu>




More information about the Python-list mailing list