From: Francesc A. <fa...@ca...> - 2005-10-25 19:09:13
|
Hi Stefan, El dl 24 de 10 del 2005 a les 08:59 -0700, en/na Stefan Kuzminski va escriure: > If I run this simple loop, I get the output I expect.. >=20 > table =3D fp.root.table_0 > for row in table: > print row >=20 > but when I call row.append(), the output changes and looks corrupted.. >=20 > table =3D fp.root.table_0 > for row in table: > print row > row.append() Yes, the ability to modify tables in the middle of iterators was not implemented yet. I've catched situations where the user tries to do something like: for row in table: row['somefield'] =3D 2 by issuing the next exception: File "test-append.py", line 42, in read_junk row['lati'] =3D 2 File "TableExtension.pyx", line 1123, in TableExtension.Row.__setitem__ NotImplementedError: You cannot set Row fields when in middle of a table iterator. Use Table.modifyRows() or Table.modifyColumns() instead. but forgot about append(). Now, I've catched this as well and a similar exception will be raised: for row in table: row.append() File "test-append.py", line 43, in read_junk row.append() File "TableExtension.pyx", line 1038, in TableExtension.Row.append NotImplementedError: You cannot append rows when in middle of a table iterator. Anyway, if what you want is modify columns on an existing table, you can use something like: for nrow in xrange(tt.nrows): row =3D tt[nrow:nrow+1] row.field('lati')[0] =3D 2 row.field('pressure')[0] =3D nrow tt.modifyRows(nrow,rows=3Drow) I'm working implementing a variant of this: for row in tt: row['lati'] =3D 2 row['pressure'] =3D row.nrow() row.modify() which looks prettier to my eyes. In addition it's much faster (up to 20x than the former version). A preliminary version of this later implementation is already in the PyTables repository and most probably will be included in PyTables 1.2 (provided that I've time to add the test units and documenting it). If this is what you want, you can have a try at the nigthly tarball that will be automatically made this night around 0:05 UTC at: http://www.carabos.com/downloads/pytables/snapshots/ Cheers, --=20 >0,0< Francesc Altet http://www.carabos.com/ V V C=E1rabos Coop. V. Enjoy Data "-" |