Use context managers to access files
Manually using open()
and H5File.close()
can lead to problems where the file is never closed (if an exception is thrown before) and therefore yields corrupt outputs. An easy solution is to use a context manager (with open():
), which automatically takes care of releasing used resources even if an exception is thrown.