From what I understand, I
is an example of a format character which represents an unsigned integer and f
is used to represent a float
But when I try to write [120,3.5,255,0,100]
to a binary file as bytes:
from struct import pack
int_and_float = [120,3.5,255,0,100]
with open ("bin_file.bin","wb") as f:
f.write(pack("IfIII",*bytearray(int_and_float)))
Output
TypeError: an integer is required
So is it not possible to store floats and integers as bytes in the same list?