If I run the commands below, the output differs between Python 2.7 and Python 3.
After spending too much time on this, I think Python 3 is doing some Unicode "magic" and is somehow converting my input (e.g. \xe0
becomes \xc3\xa0
).
How can I avoid this support?
How do I get the output from Python 2.7 in Python 3?
python2.7 -c 'print("\x10\x13\xe0\xf7\x60\x42\xdf\xf7\xac\x3b\xf2\xf7")'
python3 -c 'print("\x10\x13\xe0\xf7\x60\x42\xdf\xf7\xac\x3b\xf2\xf7")'
Further example:
If for example I pipe the output of Python into xxd I just want to get what I supplied to print and not any bonus stuff. I am not an experienced programmer but the handling of Python 2.7 seems very intuitive to me. So what must I do to obtain the same behaviour in Python 3?
$ python2.7 -c 'print("\x10\x13\xe0\xf7\x60\x42\xdf\xf7\xac\x3b\xf2\xf7")' | xxd
00000000: 1013 e0f7 6042 dff7 ac3b f2f7 0a ....`B...;...
$ python3 -c 'print("\x10\x13\xe0\xf7\x60\x42\xdf\xf7\xac\x3b\xf2\xf7")' | xxd
00000000: 1013 c3a0 c3b7 6042 c39f c3b7 c2ac 3bc3 ......`B......;.
00000010: b2c3 b70a