Natural Naming

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)
using("h5py")

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 0x71c8054f86a0>
with h5tbx.File() as h5:
    ds = h5.create_dataset('test', shape=(3,))
    print(h5.test)
<HDF5 dataset "test": shape (3,), type "<f4", convention "h5py">
/home/docs/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/stable/lib/python3.10/site-packages/h5rdmtoolbox/wrapper/core.py:1053: H5pyDeprecationWarning: Creating a dataset without passing data or dtype is deprecated. Pass an explicit dtype. Using dtype='f4' will keep the current default behaviour.
  _ds = super().create_dataset(

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 0x71c8054f9e70>
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'