detect endianness of a binary with python

Discussion in 'Python' started by Holger brunck, Jul 21, 2010.

  1. Hi all,
    I use python 2.5 and I am looking for a possibility to determine a file type.
    Especially the endianness of a file is needed for me. Is there a way to detect
    this easily in python? Something like the "file" utility for linux would be very
    helpfull.

    Any help is appreciated.

    Best regards
    Holger Brunck
    Holger brunck, Jul 21, 2010
    #1
    1. Advertising

  2. On 2010-07-21, Holger brunck <> wrote:

    > I use python 2.5 and I am looking for a possibility to determine a
    > file type. Especially the endianness of a file is needed for me. Is
    > there a way to detect this easily in python?


    Only if you already know what's going to be in the file.

    > Something like the "file" utility for linux would be very helpfull.
    >
    > Any help is appreciated.


    You're going to have to describe in detail what's in the file before
    anybody can help.

    --
    Grant Edwards grant.b.edwards Yow! A shapely CATHOLIC
    at SCHOOLGIRL is FIDGETING
    gmail.com inside my costume..
    Grant Edwards, Jul 21, 2010
    #2
    1. Advertising

  3. On 07/21/2010 08:02 AM, Grant Edwards wrote:
    > On 2010-07-21, Holger brunck <> wrote:
    >
    >> I use python 2.5 and I am looking for a possibility to determine a
    >> file type. Especially the endianness of a file is needed for me. Is
    >> there a way to detect this easily in python?

    >
    > Only if you already know what's going to be in the file.
    >
    >> Something like the "file" utility for linux would be very helpfull.
    >>
    >> Any help is appreciated.

    >
    > You're going to have to describe in detail what's in the file before
    > anybody can help.


    There is a python module called "magic" that uses the same engine as
    file to determine a file type. It's part of the "find" source code:

    http://www.darwinsys.com/file/

    On Fedora I can just yum install python-magic to get it.
    Michael Torrie, Jul 21, 2010
    #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. pramod
    Replies:
    22
    Views:
    1,796
    Lew Pitcher
    Jan 6, 2004
  2. kelvSYC

    Endianness

    kelvSYC, Jun 3, 2005, in forum: C++
    Replies:
    3
    Views:
    573
    Donovan Rebbechi
    Jun 3, 2005
  3. kelvSYC

    Endianness and streams

    kelvSYC, Jun 5, 2005, in forum: C++
    Replies:
    8
    Views:
    437
    Pete Becker
    Jun 6, 2005
  4. T Koster

    Binary-mode i/o, width of char, endianness

    T Koster, Mar 1, 2005, in forum: C Programming
    Replies:
    15
    Views:
    451
    Tim Rentsch
    Mar 3, 2005
  5. Thomas Jollans
    Replies:
    1
    Views:
    654
    Grant Edwards
    Jul 22, 2010
Loading...

Share This Page