This is my first code in python and I have this issue:
I'm reading a binary file as:
def read_file(file):
with open(file, "rb") as f:
frame = f.read()
print(type(frame)) #out = <class 'bytes'>
return frame
I need to convert all the vector to int values instead using them as bytes.
After printing I get something like this:
print(frame[0:10])
b'\xff\xff\xff\xffXabccc'
However if I print passing one position only I get this:(the integer values are correct, but I just get them using the function print)
print(frame[0])
255
print(frame[1])
255
print(frame[2])
255
print(frame[3])
255
print(frame[4])
88
print(frame[5])
97
print(frame[6])
98
print(frame[7])
99
print(frame[8])
99
print(frame[9])
99
print(frame[10])
98
The question is: How can I convert all the positions of my array in one step? I would like to run the code
print(frame[0:10])
and get something like
[255, 255, 255, 255, 88, 97, 98, 99 ,99, 99, 98]
frame
is not abytearray
, but abytes
object. Both exist in Python, but whereas the former is mutable, yourbytes
object is not.