/usr/share/doc/python-tables-doc/examples/attributes1.py is in python-tables-doc 3.1.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import numpy as np
import tables
# Open a new empty HDF5 file
fileh = tables.open_file("attributes1.h5", mode="w",
title="Testing attributes")
# Get the root group
root = fileh.root
# Create an array
a = np.array([1, 2, 4], np.int32)
# Save it on the HDF5 file
hdfarray = fileh.create_array(root, 'array', a, "Integer array")
# Assign user attributes
# A string
hdfarray.attrs.string = "This is an example"
# A Char
hdfarray.attrs.char = "1"
# An integer
hdfarray.attrs.int = 12
# A float
hdfarray.attrs.float = 12.32
# A generic object
hdfarray.attrs.object = {"a": 32.1, "b": 1, "c": [1, 2]}
# Close the file
fileh.close()
|