I have a file that contains bytes in plain text. For example:
00
01
02
A0
A1
A2
FD
FE
FF
I can read the file using:
fh = open(file, 'rb')
my_bytearray = bytearray(fh.read())
However, when I print this it returns:
print(my_bytearray)
b'00\r\n02\r\nA0\r\nA1\r\nA1\r\nA2\r\nFD\r\nFE\r\nFF'
It reads also the \r\n
at the end of each line, and also not in hex format, for example not \xFF
but FF
.
I want to read this file into a bytearray and when I print this bytearray I want to see it as:
print(my_bytearray)
b'\x00\x01\x02\xA0\xA1\xA2\xFD\xFE\xFF'
How can I achieve this?