finding byte order

Jp Calderone exarkun at divmod.com
Fri Dec 3 13:38:05 EST 2004


On Fri, 03 Dec 2004 19:19:48 +0100, "Diez B. Roggisch" <deetsnospam at web.de> wrote:
>>   I would like to have a test to tell me if the current machine is
                                               ^^^^^^^^^^^^^^^^^^^
> > using big or small endian, this way I could use the array module in
> > the first case and the *slower* struct module on the second. I looked
> > but did not find. Is there a python function to know that?
> 
> There is no such test, as it's domain-specific if there _can_ be such a test
> or not. If your data is composed in a way that you can infer the endianess
> by reading e.g. a header at the beginning that has well-known fields, then
> it might work. But only you can do that.
> 
> For a pure binary file, there is absolutely no way of telling the endianess.

  I think you misread the question.

  Jp



More information about the Python-list mailing list