[Python-ideas] Fixing the Python 3 bytes constructor

Serhiy Storchaka storchaka at gmail.com
Fri Mar 28 22:15:35 CET 2014


28.03.14 19:06, Benjamin Peterson написав(ла):
> Antoine Pitrou <solipsis at ...> writes:
>> I don't like it, but I also don't think it's enough of a nuisance to be
>> deprecated.
>> (the indexing behaviour of bytes objects is far more annoying)
>
> I agree. We would add a method that iterates over single bytes as bytes
> objects instead of integers.

More general function can be used instead.

def chunks(seq, size):
     for i in range(0, len(seq), size):
         yield seq[i: i + size]


 >>> list(chunks(b'abc', 1))
[b'a', b'b', b'c']




More information about the Python-ideas mailing list