pytables,在嵌套字段中添加行

时间:2014-04-30 08:37:06

标签: python nested pytables

从像这样的简单结构开始:

from tables import *

class subTable(IsDescription):
    subCol1= Int64Col(pos=0)
    subCol2= StringCol(itemsize=32, pos=1)
    subCol3= Int64Col(pos=2)

class mainTable(IsDescription):
    column1= Int64Col(pos=0)
    column2= StringCol(itemsize=32, pos=1)
    column3= subTable()

如果我理解文档很好,现在我有一个表(mainTable),其中包含3列(column1, column2, column3),每个column3包含另一个表,另有3列(subCol1, subCol2, subCol3) < / p>

所以,现在,用行填充主表是一件容易的事。

但是......如何在column3 ??

中的每个表中添加行

当然,如果我错了,我将不胜感激。

2 个答案:

答案 0 :(得分:1)

你不能用PyTables做到这一点。

答案 1 :(得分:0)

你所做的并没有错,只是因为我认为你不能为subTable设置多行:

from tables import *

class subTable(IsDescription):
    subCol1= Int64Col(pos=0)
    subCol2= StringCol(itemsize=32, pos=1)
    subCol3= Int64Col(pos=2)

class mainTable(IsDescription):
    column1= Int64Col(pos=0)
    column2= StringCol(itemsize=32, pos=1)
    column3= subTable()

hdf5_a = openFile("delete.hdf5", "a")
table = hdf5_a.create_table("/", "test", mainTable)

table.row['column3/subCol1'] = 10
table.append()

因此,您可以将subTable的值设为table.row['column3/subColX']。但不是多行。