我想使用Python3从hdf5文件的属性中检索字符串。
除了引号外,它的前面还有一个'b‘。如何删除b和引号?
import h5py
f = h5py.File('.../HS-L1C-FA-166db-00.hdf5', 'r')
aq_time=f['LEVEL1C']['VNIR0'].attrs['TIMESTAMP']
>>> aq_time
b'2018-11-01T11:43:55Z'
>>> aq_time[2:]
b'18-11-01T11:43:55Z'发布于 2020-06-20 08:10:18
HDF5中的所有字符串都是编码文本,因此需要进行解码。
很容易添加:
import h5py
f = h5py.File('.../HS-L1C-FA-166db-00.hdf5', 'r')
aq_time=f['LEVEL1C']['VNIR0'].attrs['TIMESTAMP'].decode('utf-8')有关h5py文档中HDF5字符串的更多信息,请单击此处:
http://docs.h5py.org/en/stable/strings.html
https://stackoverflow.com/questions/62475607
复制相似问题