Hi! This is what I use, maybe it can help you:
def addFields(self,pFieldNames,pFieldTypes,pFieldShapes,pFilters): global gvH5File global gvRoot fieldProp = [] SampleGroupName = 'DG0' if gvH5File.__contains__('/' + SampleGroupName + '/DS') == False: descr_group = gvH5File.createGroup(gvRoot,SampleGroupName) for n in range(len(pFieldNames)): if pFieldTypes[n] == 'string': fieldProp.append(Col.from_kind('string',itemsize=int(pFieldShapes[n]),shape=(),dflt=None,pos=n+1)) else: fieldProp.append(Col.from_type(pFieldTypes[n],shape=(),dflt=None,pos=n+1)) #int(pFieldShapes[n]), descrObj = dict(zip(pFieldNames, fieldProp)) table = gvH5File.createTable("/" + SampleGroupName, "DS", descrObj, "Sample table",pFilters) self.properties(descr_group) return self else: group = gvH5File.getNode("/" + SampleGroupName) dataTable = self.get(group) descrObj = dataTable.description._v_colObjects descrObjNew = descrObj.copy() for n in range(0,len(pFieldNames)): if pFieldTypes[n] == 'string': descrObjNew[pFieldNames[n]] = Col.from_kind('string',itemsize=int(pFieldShapes[n]),shape=(),dflt=None,pos=n+len(dataTable.colnames)) else: descrObjNew[pFieldNames[n]] = Col.from_type(pFieldTypes[n],shape=(),dflt=None,pos=n+len(dataTable.colnames)) #int(pFieldShapes[n]), table = gvH5File.createTable("/" + group._v_name, 'table', descrObjNew, "Sample table") for i in xrange(dataTable.nrows): table.row.append() table.flush() #for col in descrObj: # getattr(table.cols, col)[:] = getattr(dataTable.cols, col)[:] dataTable.remove() table.move("/" + group._v_name,'DS') self.properties(group) return self --- On Thu, 4/16/09, Toby Mathieson <tobymathie...@googlemail.com> wrote: > From: Toby Mathieson <tobymathie...@googlemail.com> > Subject: [Pytables-users] adding extra columns to existing table > To: pytables-users@lists.sourceforge.net > Date: Thursday, April 16, 2009, 2:27 PM > Hi all, > I think I am still thinking in terms of relational > databases and > MySQL... but now I would like to add a column to an > existing HDF5 > table... I tried something like the following: > > h5file.setNodeAttr(group,'cancelled',Int32Col(),name='Pdata') > > where 'group' is a groupNode of the table I want to alter > and 'Pdata' > is the corresponding table to which I would like to add the > attribute > (column name ) 'cancelled' and with the type Int32.... > > This doesn't throw an error, but doesn't work either. > > I also tried: > > h5file.setNodeAttr(pnode,'cancelled',Int32Col() > where pnode is the actual node (table) I am trying to > alter... but > that had no effect either > > I was pretty sure this wasn't the correct method to use > here, but > failed to find anything else! > > Which is the best way to do this? I have tried > looking through the > tutorial / help, but have obviously not used the correct > search terms. > > Any ideas? > > thanks very much > > Toby > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside > and > around Java (TM) technology - register by April 22, and > save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San > Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Pytables-users mailing list > Pytables-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pytables-users > ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users