adding a text in bytes char by char into a vector in python

Marta :

I wanted to read my text character by character and put that into a vector in bytes. After printing i see values of these characters in ASCII code. How can i fix this.

Heres my code:

text = b'ala ma kota a marysia ma rysia00'

t = []
def padding(txt):
    if len(txt) % 16 != 0:
        txt += b'0' * (16 - len(txt) % 16)
    print(txt)
    for i in range(len(txt)):
        t.append(txt[i])

padding(text)
print(t)

My output looks like this: [65, 108, 97, 32, 109, 97, 32, 107, 111, 116, 97, 32, 97, 32, 77, 97, 114, 121, 115, 105, 97, 32, 109, 97, 32, 114, 121, 115, 105, 97, 48, 48] And should look like this: [b'a', b'l', b'a', b' ', b'm', b'a', b' ', ..............]

cad_user2020 :

One can simply use the list() method.

text = 'ala ma kota a marysia ma rysia00'
t = list(text)
print(t)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=408289&siteId=1