[Python] Iterate over individual bytes in Python 3

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    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() for b in b'123']
    [b'1', b'2', b'3']

    Continue reading...

Compartilhe esta Página