[Yet another bounce (this one is more recent)]

On Thu, 4 Sep 2008 17:24:07 +0200, Ilya Kolpakov wrote:
> Hi
>
> I would like to store some dates in a table in a transparent way,
> i.e. to be able to easily assign/retrieve (for example) datetime.date
> objects.
>
> something like
> row = table.row
> row['date'] = datetime.date.today()
> or
> d = row['date']
> d = d + datetime.timedelta(30) etc
>
> The dates are easily stored as timestamps (toordinal(),
> fromordinal()), so I guess this should be pretty easy.
>
> As far as I undestand, I have to  replace  __getitem__ and
> __setitem__ methods of the actual Column instance which will handle
> this column, but don't know how to do this properly.
>
> More specifically, I don't know how to set up the table so it will
> have the right Column subclass I provide to handle my columns filled
> with dates.
>
> Could this be done? Maybe for dates its not so useful, but I can
> imagine a lot of situations when this would be really nice to have.
> Especially if the Column
> is able to store some "metadata" somewhere (in the table's attributes
> I guess) and retrieve them when being initialized.

Well, there is a bit of magic in this.  The ``Column`` classes are just 
declarative, and the assignation and retrieving of field values is 
actually done in the tableExtension.pyx extension through the typical 
__setitem__ and __getitem__ special methods.

As its extension suggests, this extension is done in Pyrex (for speed 
purposes), so you would need to learn a bit about it before knowing how 
to overload methods in extensions (I've never done that, but I suppose 
that this is feasible).  If you get into trouble, ask here, or better 
yet, in the Pyrex list.

Finally, please report your progress as I'm interested in this subject 
as it opens interesting possibilities.

Good luck!

-- 
Francesc Alted
Freelance developer
Tel +34-964-282-249

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to