检查h5py中是否存在节点 [英] Check if node exists in h5py
本文介绍了检查h5py中是否存在节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种简单的方法可以使用h5py检查HDF5文件中是否存在节点.
I am wondering if there is a simple way to check if a node exists within an HDF5 file using h5py.
我在文档中找不到任何内容,所以现在我正在使用异常,这很丑.
I couldn't find anything in the docs, so right now I'm using exceptions, which is ugly.
# check if node exists
# first assume it exists
e = True
try:
h5File["/some/path"]
except KeyError:
e = False # now we know it doesn't
添加上下文:我正在使用它来确定节点是否存在,然后再尝试创建具有相同名称的新节点.
To add context: I'm using this to determine if a node exists before trying to create a new node with the same name.
推荐答案
e = "/some/path" in h5File
做到了. Group
文档中非常简短地提到了这一点.
does it. This is very briefly mentioned in the Group
documentation.
这篇关于检查h5py中是否存在节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文