From: Francesc A. <fa...@ca...> - 2008-01-07 12:32:22
|
Hi Luca, A Monday 07 January 2008, Ivan Vilata i Balaguer escrigu=C3=A9: > Luca Della Santina (el 2008-01-07 a les 11:16:25 +0100) va dir:: > >[...] > > I would like to modify the value contained in the third column of > > the second row from the original value of 4 to 5 but couldn't find > > a quick way to do it inside the pytables manual. > > > > In first stance i tried to: > > mytable[1][2] =3D 5 > > mytable.flush() > > > > but in this way the new value is not written into the table (even > > if no errors were reported). This is because you should understand what's going on under the hood. =20 When you call mytable[1], this returns a row of the table as a NumPy=20 scalar (of 'void' type), and hence mytable[1][2] will set the 3rd=20 field of such (temporal) scalar. So, the result is that your code=20 won't do nothing. > ``Table.modifyColumn()`` is your friend:: > > mytable.modifyColumn(start=3D1, colname=3D'name_of_field2', > column=3D[5]) mytable.flush() You can use also the .cols accessor, which is slightly more confortable=20 IMO: mytable.cols.name_of_field2[1] =3D 5 or, if you prefer using the field index instead of the name: mytable.cols._f_col(mytable.colnames[2])[1] =3D 5 BTW, a Table.flush() is only needed when you append/modify the Table=20 using an iterator, so you don't need to issue it in this case. Ciao, =2D-=20 >0,0< Francesc Altet =C2=A0 =C2=A0 http://www.carabos.com/ V V C=C3=A1rabos Coop. V. =C2=A0=C2=A0Enjoy Data "-" |