Estoy experimentando con bytes
vs bytearray
en Python 2.6. No entiendo el motivo de algunas diferencias.bytes vs bytearray en Python 2.6 y 3
A bytes
iterador devuelve cadenas:
for i in bytes(b"hi"):
print(type(i))
da:
<type 'str'>
<type 'str'>
Sin embargo, un iterador bytearray
retornos int
s:
for i in bytearray(b"hi"):
print(type(i))
da:
<type 'int'>
<type 'int'>
¿Por qué la diferencia?
Me gustaría escribir un código que se traduzca bien en Python 3. Entonces, ¿la situación es la misma en Python 3?
Para obtener más información, consulte: http://docs.python.org/whatsnew/2.6.html#pep-3112-byte-literals y http://docs.python.org/3.1/library/stdtypes.html# sequence-types-str-bytes-bytearray-list-tuple-range –