I need to write text, then binary data to a file. For example, I would like to write the file with contents:
BESTFORMAT
NUMLINES 42
FIELDS FOO BAR SPAM
DATATYPES INT32 FLOAT64 FLOAT64
FILETYPE BINARY
???d?'Ӈ T???'Ѥ??X??\??
?? R??&??X??\???????
??zR??X??\????????
...
However, in Python you can't open a file in a way that you can write ASCII data, then binary data.
I've tried:
Converting my binary data to text (no good, as it outputs
b'5 42.7 0.8'
Encoding my text data to binary and opening the file as binary (no good, as then I have a binary file). Edit: it turns out this was working, but I needed to open the file in my text editor with UTF-8 encoding