Jun-07-2020, 06:16 AM
Hello,
I try to put 128 values into a struct to write this data of the struct to a file. This is my code:
I tried different code snippets from the web, but none did work. Can you help me?
Thank you in advance,
Bernhard
I try to put 128 values into a struct to write this data of the struct to a file. This is my code:
import struct values = [] for value in range(0, 128): values.append(value) value_data = [chr(value) for value in values] value_obj = struct.Struct('%dc' % 128) value_data_packed = value_obj.pack(*value_data) f = open('test.bin', "wb") f.write(value_data_packed) f.close()I always received the struct.error: char format requires a bytes object of length 1
I tried different code snippets from the web, but none did work. Can you help me?
Thank you in advance,
Bernhard