From: Francesc A. <fa...@ca...> - 2005-01-25 17:27:50
|
Hi Norbert, The Table.row object is only defined as a mean to allow fast appends to Table objects, and it was designed to work only with this goal. I agree with you in that allowing: for row in mytable.iterrows(): row['x'] =3D row['x'] + 0.5 would be nice, but the problem is that Row.__setitem__ only puts its value in a buffer, that is intended to be written to disk afterwards. An easy workaround would be defining a new class, say RowMod (for Row Modification), so that its __setitem__ method would work as you want. Once we have this, mytable.iterrows() would return instances of class RowMod,=20 not Row. That way, the next should work: row =3D mytable.row for i in range(3): row['x'] =3D i row.append() mytable.flush() but also, for row in mytable.iterrows(): row['x'] =3D row['x'] + 0.5 Mmm, I'll think more on that, and if I find this feasible (and more importantly, find the time), I'll try to implement that. By the way, a good workaround for what you are trying for is: for i in xrange(mytable.nrows): mytable.cols.x[i] =3D mytable.cols.x[i] + 0.5 Cheers, A Dimarts 25 Gener 2005 15:51, Norbert Nemec va escriure: > Hi there, > > i would have assumed that the following works: > ------------------------- > #!/usr/bin/env python > > from tables import * > > file =3D openFile('tryout.h5','w') > > desc =3D {} > desc['x'] =3D FloatCol() > > file.root.mytable =3D Table(desc) > mytable =3D file.root.mytable > > row =3D mytable.row > for i in range(3): > row['x'] =3D i > row.append() > mytable.flush() > > for row in mytable.iterrows(): > row['x'] =3D row['x'] + 0.5 > mytable.flush() > > for row in mytable.iterrows(): > print row['x'] > > file.close() > ------------------------- > > but obviously, the writing is completely ignored. Is this intuitive > approach wrong? Is it just not implemented yet? Is there some other way t= he > same thing could be done? > > Ciao, > Norbert =2D-=20 >qo< Francesc Altet =A0 =A0 http://www.carabos.com/ V =A0V C=E1rabos Coop. V. =A0=A0Enjoy Data "" |