Behaviour of filehandle.readlines() for images on Windows

Alex Martelli aleax at aleax.it
Tue Oct 14 12:43:43 EDT 2003


Jorge Godoy wrote:

> I'm trying to get a specific information from inside an image and it
> works correctly on unices. What I do is:
> 
>   1. associate a filehandle with the image file
>   2. get the desired line
>   3. read the amount of data I want
>   4. close the filehandle
> 
> 
> While using Windows it only gets the first line with the signature of
> the file. Any ideas on how to accomplish the same task?
> 
> I'm wondering if it has something to do with either (or both) the
> magic treatment Windows gives to files trying to open them with some
> specific program or the line ending convention (these images show fine
> on Windows but were generated on a Linux box).

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.


Alex





More information about the Python-list mailing list