A Divendres 24 Desembre 2004 06:22, Andrew Straw va escriure:
> Should I be able to do something like the following?
>=20
> for row in table:
> row['y'] =3D row['x'] + 2
>=20
> If so, how do I commit these changes to disk? table.flush() doesn't seem=
=20
> to work.
Well, you can do something like:=20
# Modify field 'y'
table.cols.y[:] =3D table.cols.x[:]+2
# Modify rows 1 to the end with an stride of 2 in field 'y'
table.cols.y[1::2] =3D table.cols.x[1::2]+2
Which is equivalent to:
# Modify field 'y'
table.modifyColumns(start=3D1, columns=3D[[table.cols.x[1]+2]], names=3D=
["y"])
# Modify rows 1 to the end with an stride of 2 in field 'y'
columns =3D numarray.records.fromarrays([table.cols.x[1::2]+2], formats=
=3D"i4")
table.modifyColumns(start=3D1, step=3D2, columns=3Dcolumns, names=3D["y"=
])
[Example taken from the pytables user's manual (Column.__setitem__ section),
just slightly adapted to your example]
> It seems like this simple example should be in the tutorial and the unit=
=20
> tests, but I can't find it anywhere. ("How to edit a row") =20
Maybe I should improve the manual, most specially adding a tutorial for
value modification.
Cheers,
=2D-=20
=46rancesc Altet =A0 >qo< =A0 http://www.carabos.com/
C=E1rabos Coop. V. =A0 V =A0V =A0 Enjoy Data
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ""
|