eerimoq / bincopy

Mangling of various file formats that conveys binary information (Motorola S-Record, Intel HEX, TI-TXT, Verilog VMEM, ELF and binary files).
MIT License
109 stars 38 forks source link

save the object bincopy.BinFile #24

Closed fncode246 closed 2 years ago

fncode246 commented 2 years ago

I want to extract the data from S19 file. I decided to convert it to binary in this way (as it is done in:https://stackoverflow.com/questions/24110121/how-to-manipulate-srec-file/45465864#45465864)

import bincopy
f = bincopy.BinFile()
f.add_srec_file("New.s19")
f.as_binary()

Then I want to save this object and extract data part. I use .write to save but it has "TypeError: write() argument must be str, not BinFile" error.

with open('out.txt', 'w') as w:
    w.write(f)

How should i save it and what is your idea? Thanks

eerimoq commented 2 years ago
import bincopy
f = bincopy.BinFile()
f.add_srec_file("New.s19")

with open('out.txt', 'wb') as w:
    w.write(f.as_binary())