Python: Reading bytes from a file and converting it to the needed type

61 Views Asked by At

I am trying to implement a code which reads the bytes from a file and computes the histogram of the byte count frequencies:

I am using this code to read from a file and writing to a csv file:

block_size = int(block_size)
data_block = data[:block_size]
encoded_data_block = base64.b64encode(data_block).decode("utf-8")
csv_writer.writerow([encoded_data_block, label])

later on, I am trying to read from the csv file to compute the byte count:

for example, one of the rows in my csv file looks something like this:

b'a2pUuzNscSX+UaAz9KAMtls+OeN08DtLa4WYri76IouKLNp+iXaKntSqKBQZLqIdG/xt4GWiXD08nI

in an example dataset and code that i am referring to, the rows of the csv file are looking like this:

b'x\x9c\x9c\xbd\xcb\x8e\x1cW\x96-8\xe7W\x18\x1c(\x88\x04<\x02\x0c\xea\x9d\x1aQ$\xf5*QR\x89\xcc\xd2\xbdU\xa8\x81\xb9\xdb\xf1p\x13\xcd\xcd<\xed\x11A\xd7(q\xd1

i want my dataset rows also to be like above, so that i can test my code against theirs. can anyone please help in how can i get my data to be of the above format?

0

There are 0 best solutions below