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

Jen Kris jenkris at tutanota.com
Mon Oct 2 11:06:08 EDT 2023


My previous message just went up -- sorry for the mangled formatting.  Here it is properly formatted:

I want to write a list of 64-bit integers to a binary file.  Every example I have seen in my research converts it 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)
    for offset in range(len(qs_array)):
        item_to_write = bytes(qs_array[offset])
        struct.pack_into(buf, "<Q", offset, item_to_write)

But I get the error "struct.error: embedded null character."  

Maybe there's a better way to do this?  

Any help will be very appreciated.  



More information about the Python-list mailing list