Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 4726f970c4b56b9a0ebb9a03a0b6522e > files > 8

python-tables-doc-3.0.0-4.mga4.noarch.rpm

from numpy import *
from tables import *

# Open a new empty HDF5 file
fileh = open_file("attributes1.h5", mode = "w", title="Testing attributes")
# Get the root group
root = fileh.root

# Create an array
a = array([1, 2, 4], 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()