[Python] Bytes type is required

Discussão em 'Python' iniciado por Stack, Agosto 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am getting the error message

    data_new.write(binary_data[j])
    TypeError: a bytes-like object is required, not 'int'


    although binary_data should be bytes-like.

    data_new = open(Datei_neu, "wb")

    for j in range(0,43,1):
    data_new.write(binary_data[j])


    As soon as the code is extended by bytes(), then the error does not appear anymore:

    data_new = open(Datei_neu, "wb")

    for j in range(0,43,1):
    data_new.write(bytes(binary_data[j]))



    But secondly, there is nothing written into Datei_neu, although binary_data is representing all values from position 0..43.

    Continue reading...

Compartilhe esta Página