python - Behavior change of bytes from py2 to py3 -


i got curious after discussion taking place on this question. appears behavior of bytes() has changed in python3. in the docs py3 listed built-in function behaves same bytearray() except result being immutable. doesn't appear in same place in py2 docs.

in digging thru docs while couldn't find detailing what's changed 2 3, looks has. what's difference , why changed?

from linked question in comments remarked respect py3

bytes(1) returns b'00'

but in 2.7.5

>>> bytes(1) '1' 

the python 3 bytes constructor takes optional int parameter specifying number of bytes output. bytes initialized 0 (\x00) constructor, bytes(1) == b'\x00'.

the python 2 bytes constructor identical str, , therefore stringizes argument:

python 2.7.5 (v2.7.5:ab05e7dd2788, may 13 2013, 13:18:45)  [gcc 4.2.1 (apple inc. build 5666) (dot 3)] on darwin type "help", "copyright", "credits" or "license" more information. >>> bytes str true 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -