attributes - 使用python从hdf5文件中检索属性
问题描述
我想使用 Python 3 从 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'
解决方案
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
推荐阅读
- delphi - 休息调试器参数无法正常工作
- c# - 如何使用 C# 从我的公司 gmail 地址通过 SMTP 发送电子邮件
- c# - 为什么 Visual Studio 监视窗口显示集合中 ValueTuples 的错误值?
- sql - 相同的 ruby on rails 查询返回不同的值
- ionic-framework - 单击特定的 ion-item 按钮会触发其他按钮
- python - Python & MySQL 连接器:AttributeError:'CMySQLCursor' 对象没有属性'next'
- r - 在R中的数据块上使用doparallel嵌套foreach
- c# - 按 F5 时重建未引用的其他项目
- c# - 无法在 Xamarin 表单中以发布模式构建解决方案
- javascript - 尝试使用 Sendgrid 发送电子邮件后出现网络错误