Natural Naming#
h5RDMtoolbox supports attribute style access (natural naming) on datasets, groups and attributes instead of the known dictionary style. This means that HDF objects must not be named as existing attributes of used instances, e.g. File.
import h5rdmtoolbox as h5tbx
h5tbx.use(None)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import h5rdmtoolbox as h5tbx
2 h5tbx.use(None)
File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/checkouts/v1.7.0/h5rdmtoolbox/__init__.py:129
125 with File(src) as h5:
126 return h5.dumps()
--> 129 from h5rdmtoolbox.wrapper.ld.hdf.file import get_ld as hdf_get_ld
130 from h5rdmtoolbox.wrapper.ld.user.file import get_ld as user_get_ld
133 def get_ld(
134 hdf_filename: Union[str, pathlib.Path],
135 structural: bool = True,
136 semantic: bool = True,
137 blank_node_iri_base: Optional[str] = None,
138 **kwargs) -> rdflib.Graph:
File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/checkouts/v1.7.0/h5rdmtoolbox/wrapper/ld/__init__.py:1
----> 1 import ssnolib.ssno.standard_name
2 from ontolutils.namespacelib import M4I
3 from ontolutils.namespacelib import SCHEMA
ModuleNotFoundError: No module named 'ssnolib'
You can enable natural naming by the following line. However, True is the default.
h5tbx.set_config(natural_naming=True)
<h5rdmtoolbox._cfg.set_config at 0x1e30a21aca0>
with h5tbx.File() as h5:
ds = h5.create_dataset('test', shape=(3,))
print(h5.test)
<HDF5 dataset "test": shape (3,), type "<f4", convention "h5py">
Disabeling the natural naming configuration will raise an AttributeError when running the above code:
h5tbx.set_config(natural_naming=False)
<h5rdmtoolbox._cfg.set_config at 0x1e30a21a910>
with h5tbx.File() as h5:
ds = h5.create_dataset('test', shape=(3,))
try:
print(h5.test)
except Exception as e:
print(e)
'File' object has no attribute 'test'