Behaviour of filehandle.readlines() for images on Windows

J

Jorge Godoy

Hi!


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).


TIA,
 
A

Alex Martelli

Jorge said:
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
 
J

Jorge Godoy

Alex Martelli said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top