Skip to content Skip to sidebar Skip to footer

How Can The Shape Of A Pytables Table Column Be Defined By A Variable?

I'm trying to create an IsDescription subclass, so that I can define the structure of a table I'm trying to create. One of the attributes of the subclass** needs to be shaped given

Solution 1:

Use a dictionary to define the table instead of subclassing IsDescription.

import tables
import numpy as np
param = 10
with tables.open_file('save.hdf','w') as saveFile:
    tabledef = {'var1':tables.Float64Col(shape=(param))}
    table = saveFile.create_table(saveFile.root,'test',tabledef)
    tablerow = table.row
    tablerow['var1'] = np.array([1,2,3,4,5,6,7,8,9,0])
    tablerow.append()
    table.flush()
with tables.open_file('save.hdf','r') as sv:
    sv.root.test.read()

Post a Comment for "How Can The Shape Of A Pytables Table Column Be Defined By A Variable?"