[Tutor] could somebody please explain...

Clayton Kirkwood crk at godblessthe.us
Wed Oct 1 18:07:02 CEST 2014



!-----Original Message-----
!From: Danny Yoo [mailto:dyoo at hashcollision.org]
!Sent: Wednesday, October 01, 2014 12:11 AM
!To: Clayton Kirkwood
!Cc: Python Tutor Mailing List
!Subject: Re: [Tutor] could somebody please explain...
!
!> Also, I found something that I can’t get my mind around. It is part of
!> the time/date protocols. I’ve not seen it anywhere else.
!>
!> Datetime(year=blah, blah, blah).date/time()
!>
!> datetime(2013,3,6).date() #returns…
!> datetime.date(2013,3,6)
!>
!> datetime(2013,3,6).time() #returns…
!> datetime.time(0,0)
!>
!> This is one of the weirder things I’ve run across. Is this
!> allowed/needed in other functions/classes, or is it a datetime thing
!only?
!
!
!Can you say more about what you expect?  It may help to be very
!explicit, even if it seems silly.  The problem with talking with
!experienced tutors and programmers is that our perspective has warped
!slightly from extended exposure.  :P  So we may need a bit of hinting to
!tell what you're referring to by weirdness.
!

Sure, the interest is regarding the '2013,3,6' in the first datetime. I've not seen something in the first set of parenthesis before. Is the first one a class or a function, how can you tell without looking at its internals or some documentation?

!
!The datetime library, if I recall correctly, combines two things: the
!date part, and the time part, each which are otherwise treated
!separately.  It's a composite object.
!
!    https://docs.python.org/2/library/datetime.html#datetime-objects
!
!When we construct a datetime.datetime, at the very least we need to
!provide its year, month, and day, but the other "time" components of it
!are optional.  That's what the documentation is trying to say when it
!wraps the arguments in braces here:
!
!    https://docs.python.org/2/library/datetime.html#datetime.datetime
!
!If you don't provide the time-related arguments, I think it assumes that
!those components are zeroed out.

Yes, but apparently you can also specify the specific handle in any order like a dict. Somewhat.

Clayton Kirkwood




More information about the Tutor mailing list