Behaviour of filehandle.readlines() for images on Windows

Discussion in 'Python' started by Jorge Godoy, Oct 14, 2003.

  1. Jorge Godoy

    Jorge Godoy Guest

    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,
    --
    Godoy. <>
     
    Jorge Godoy, Oct 14, 2003
    #1
    1. Advertising

  2. 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
     
    Alex Martelli, Oct 14, 2003
    #2
    1. Advertising

  3. Jorge Godoy

    Jorge Godoy Guest

    Alex Martelli <> 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. <>
     
    Jorge Godoy, Oct 14, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leeds, Mark

    \r for newline in readlines function

    Leeds, Mark, Sep 19, 2003, in forum: Python
    Replies:
    3
    Views:
    325
    David Eppstein
    Sep 19, 2003
  2. Skip Montanaro

    RE: \r for newline in readlines function

    Skip Montanaro, Sep 19, 2003, in forum: Python
    Replies:
    0
    Views:
    664
    Skip Montanaro
    Sep 19, 2003
  3. Richard
    Replies:
    5
    Views:
    323
    Hari Pulapaka
    Aug 13, 2004
  4. Uwe Mayer

    blocking file.readlines() needed

    Uwe Mayer, Aug 13, 2004, in forum: Python
    Replies:
    2
    Views:
    254
    Peter Otten
    Aug 13, 2004
  5. Replies:
    2
    Views:
    109
Loading...

Share This Page