Hi Luca,

A Monday 07 January 2008, Ivan Vilata i Balaguer escrigué:
> 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] = 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.  
When you call mytable[1], this returns a row of the table as a NumPy 
scalar (of 'void' type), and hence mytable[1][2] will set the 3rd 
field of such (temporal) scalar.  So, the result is that your code 
won't do nothing.

> ``Table.modifyColumn()`` is your friend::
>
>     mytable.modifyColumn(start=1, colname='name_of_field2',
> column=[5]) mytable.flush()

You can use also the .cols accessor, which is slightly more confortable 
IMO:

mytable.cols.name_of_field2[1] = 5

or, if you prefer using the field index instead of the name:

mytable.cols._f_col(mytable.colnames[2])[1] = 5

BTW, a Table.flush() is only needed when you append/modify the Table 
using an iterator, so you don't need to issue it in this case.

Ciao,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to