Sto sperimentando con bytes
in bytearray
in Python 2.6. Non capisco la ragione di alcune differenze.byte vs bytearray in Python 2.6 e 3
A bytes
iteratore restituisce stringhe:
for i in bytes(b"hi"):
print(type(i))
dà:
<type 'str'>
<type 'str'>
Ma un iteratore bytearray
rendimenti int
s:
for i in bytearray(b"hi"):
print(type(i))
dà:
<type 'int'>
<type 'int'>
Perché la differenza?
Mi piacerebbe scrivere codice che si traduca bene in Python 3. Quindi, la situazione è la stessa in Python 3?
Per maggiori informazioni visita: http://docs.python.org/whatsnew/2.6.html#pep-3112-byte-literals e http://docs.python.org/3.1/library/stdtypes.html# sequence-types-str-bytes-bytearray-list-tuple-range –