You don't say what you're doing in
# do my edits in a secon time...
but that aside, the line
edit_data= str (data.read () )
will quite drastically change your data. You're opening a binary file, converting the contents to a string, and then saving the contents to a different file, this will change things.
edit_data = data.read()
Changing to above will fix the snippet that you've provided, but if you're editing the data elsewhere this will also change things.
Suggestion
If you're going to be editing binary files a lot, it might be a good idea to use the with
syntax
with open(my_file, 'rb+') as fo:
edit_data = fo.read()
and then you don't have to worry about closing the file and so on. Once you have edit_data
, this will be an array of bytes that you can edit in place before saving your data again
with open(my_out_file, 'wb') as fo:
fo.write(edit_data)
much cleaner and simpler!