This is a good question, and I'm glad someone raises "how to you think abou
this" once in a while.

This is not (very much) about web2py - this is about python objects, and
being aware of what it is you are manipulating...  and where it is coming
from.

Basically, databases store a binary value; there is a posix definition of
timestamp values.  You can see how python datetime.date gets this - look at
dattetime.date.fromtimestamp(), or datetime.time.fromtimestamp()...

While databases do not necessarily store the POSIX notion of a timestamp,
the idea is there - its a binary blob, and to reconstitute it into some
structure takes processing - .fromtimestamp() does this.

Timestamps are time representations where the instance is important, the
specific aspects of the time less so.   It is an efficient way to grab and
store.

On python, things are held in a structure since it's already easy to do it
that way (and it makes sense, what with the pervasiveness of dicts).  The
datetime.date (and datetime.datetime) has attributes - structure that holds
the time valuse individually, logically.

So look at this a bit:

if you use ipython, and then what Massimo suggests, here are some key things
you should pay attention to (w.r.t. your question about day() versus day):

db.a.dts  --- is a SQLField object

SQL standards define timestamps, and individual databases store their own
way internally - but  an SQL timestamp is this kind-of-thing:  a blob you
have to operate on to get back the structure it holds within.

How do you find details of what that object contains (yuo defined it as a
'datetime', so you know that)?
if  you look at:

type(db.a.dts.day)

you will see it is an "instancemethod" ---  that is, a bound method
SQLField.day, bound to a particular instance of an SQLField object.

If you now look at:

type(request.now.day)   it is an int, an attribute (value) of
datetime.datetime.

And so, you see, there really should be no confusion about this - just as
Massimo says - once you have the right perspective.  It's about where things
are coming from, and what shape / structure they have in each of those
places -  and how you inspect the details about their form as they cross
from one place to another.


On Sun, Apr 26, 2009 at 2:53 PM, Álvaro Justen [Turicas] <
alvarojus...@gmail.com> wrote:

>
> On Sun, Apr 26, 2009 at 4:45 PM, weheh <richard_gor...@verizon.net> wrote:
> > I tried your suggestion but it didn't do a lot to clarify for me. I'm
> > interested in learning the exact python terminology to refer to day
> > and day(). Is day() a method of db.a.dts class? Is day an element of
> > request.now?
>
> Try dir(X), help(X), type(X) where X is:
> db.tables
> db.a
> db.a.dts
> db.a.dts.day()
> request.now
> request.now.day
>
> and read class SQLDB in gluon/sql.py (pay attention in function
> define_table).
>
> I suggest you to learn some Python introspection things.
>
> --
>  Álvaro Justen
>  Peta5 - Telecomunicações e Software Livre
>  21 3021-6001 / 9898-0141
>  http://www.peta5.com.br/
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to