How to write list of integers to file with struct.pack_into?

Jen Kris jenkris at tutanota.com
Sun Oct 1 18:04:28 EDT 2023


Iwant to write a list of 64-bit integers to a binary file.  Everyexample I have seen in my research convertsit to .txt, but I want it in binary.  I wrote this code,based on some earlier work I have done:




buf= bytes((len(qs_array)) * 8)

foroffset in range(len(qs_array)):


item_to_write= bytes(qs_array[offset])


struct.pack_into(buf,"<Q", offset, item_to_write)





ButI get the error "struct.error: embedded null character."





Maybethere's a better way to do this?





Anyhelp will be very appreciated.


Thanks.  






More information about the Python-list mailing list