Python2 vs. python3 on a line containing hex

Consider this using python 3.4

:

% python3
Python 3.4.2
% echo `python3 -c "print('a' * 72 + '\xff\xbe\xbf\xff')"` | hexdump -x
0000000    6161    6161    6161    6161    6161    6161    6161    6161
*
0000040    6161    6161    6161    6161    bfc3    bec2    bfc2    bfc3
0000050    000a                                                        
0000051

      

and this one using python 2.7.9

:

% python2 --version
Python 2.7.9
% echo `python2 -c "print('a' * 72 + '\xff\xbe\xbf\xff')"` | hexdump -x
0000000    6161    6161    6161    6161    6161    6161    6161    6161
*
0000040    6161    6161    6161    6161    beff    ffbf    000a        
000004d

      

Is this really an python 3.4

implementation bug ?

+3


source to share


1 answer


Python 2s plain- '

quoted strings represent byte strings; Python 3s represent strings of characters. The counterpart language equivalents are bytes

( b'literal'

) and unicode

( u'literal'

), respectively.



% python3 -c "from sys import stdout; stdout.buffer.write(b'a' * 72 + b'\xff\xbe\xbf\xff\n')" | hexdump -x

      

+3


source







All Articles