import tables

# Record definition
class NestedRecord(tables.IsDescription):
    class TCol(tables.IsDescription):
        sc1 = tables.StringCol(10)
        sc2 = tables.StringCol(10)
        sc3 = tables.IntCol()
    value = tables.FloatCol()

f = tables.openFile('/tmp/prova.h5', 'w')
t = f.createTable('/', 'nested_table', NestedRecord)

# Fill the nested table with 10 rows:
for i in range(10):
    t.row['TCol'] = (chr(ord('A')+i),chr(32+i),i)
    t.row['value'] = i**2
    t.row.append()
t.flush()

# Print the contents:
print "nested_table:\n", t[:]
# Only the nested columns (keys):
print "nested column:\n", t.cols.TCol[:]

# Search a value by key entry:
for row in t:
    if row['TCol'] == ('D', '#', 3):
        print "\nBingo! Key found in row #", row.nrow,
        print ".  Value:", row['value']

f.close()
