nanophotonics/nplab

h5 string reading returns bytes in h5py>3.0

Closed this issue · 0 comments

More of a curiosity than a real issue as i've implemented a quick fix for this. The issue seems to be that on newer (3.9) versions of python accessing a string saved in .h5 returns a bytes object, but in older versions returns a string. As saving timestamps saves encoded strings as attributes, they're now read as bytes. Apparently saving them as strings would read them as strings as this is the default behaviour for dataset attributes.

https://docs.h5py.org/en/latest/whatsnew/3.0.html
"Variable-length UTF-8 strings in datasets are now read as bytes objects instead of str by default, for consistency with other kinds of strings. See Strings in HDF5 for more details."