Closed fbergmann closed 2 years ago
actually, trying out different encodings, only to have them all fail, i think it would be best if you just write binary (using open mode "wb"), that way no matter what was written into the StringIO buffer, you can write it out.
Could you provide an example to reproduce the error? On which OS did it happen? Want to make sure it's not an error from somewhere else.
the file, i sent earlier has the issue. The problem came about, since when i created the file earlier by running Cephalexin_Synthesis_Model4.ipynb
the history.log created was written out as ANSI code (since the enzymeml writer did not specify an encoding, it takes the in this case windows native encoding). For example the file i mailed around earlier will have the problem.
Then if that file is read again by the enzymemlreader, and consequently written out by the enzymeml writer, the issue occurs.
so i recreated the file using the python notebook mentioned above with:
with open(history_path, "w", encoding='utf-8') as f:
f.write(enzmldoc.log.getvalue())
in the reader. Then i can roundtrip the files. (it will still fall over the old file that i mailed around earlier). So the only alternative is to write the file as binary, and manually encoding the string returned from the stringio object. there you then have the option of specifying what should happen in case of error:
Thanks for fixing that! I would propose that on failure an empty history file will be written. Otherwise the reader might thrown an error if there is none.
I currently have the issue that the code does not allow writing out documents because writing the history failed:
It is important that the encoding is defined when writing the history. If you dont different operating systems will use different encodings.