Writing bytes to stdout reverses the bytes

Grant Edwards grant.b.edwards at gmail.com
Sun Aug 19 20:45:49 EDT 2018


On 2018-08-20, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> When I write bytes to stdout, why are they reversed?
>
> [steve at ando ~]$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump
> 0000000 84fd 0804 000a
> 0000005

They aren't.  You're being fooled by the default output format of
hexdump.  By default, it displays data as 16-byte integers in
little-endian.  If you want to look at bytes, do this:

$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump -C
00000000  fd 84 04 08 0a                                    |.....|
00000005





More information about the Python-list mailing list