When iterating over a bytes
object in Python 3, one gets the individual bytes
as ints
:
>>> [b for b in b'123']
[49, 50, 51]
How to get 1-length bytes
objects instead?
The following is possible, but not very obvious for the reader and most likely performs bad:
>>> [bytes([b]) for b in b'123']
[b'1', b'2', b'3']
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…