time, calendar, datetime, etc

Steven Taschuk staschuk at telusplanet.net
Thu Jul 31 02:06:59 EDT 2003


Quoth Kylotan:
  [...]
> And does datetime.timetuple() actually return something equivalent to
> a struct_time as used by the time module? At first glance this looks
> to be true, but it isn't clearly documented as such.

Isn't it?

    timetuple()
        Return a 9-element tuple of the form returned by time.localtime().

<http://www.python.org/doc/current/lib/datetime-datetime.html>

> Personally I think 2 separate modules (1 high level, 1 low level
> corresponding to the C api) would suffice, or even to combine it all
> into one coherent module. Is there any benefit to the status quo that
> I am missing?

The bulk of the calendar module deals with creating and printing
strings and arrays representing calendar months.  Hardly
general-purpose; I wouldn't want to see such things in the
datetime module.

The exception, as you noted, is calendar.timegm(), which, indeed,
the docs describe as "unrelated but handy".

> PS. I use 'time.strptime(myTime, '%a %b %d %H:%M:%S %Y')' as a
> reverse-asctime(), and was surprised that I couldn't find this wrapped
> in a function in any of the modules. Maybe such a function would be
> considered for future addition?

Maybe indeed.

One consideration here is that the time module is, I think,
intended simply as a wrapper over the underlying C API.  Afaik
that API doesn't have convenience inverses of gmtime or asctime.

-- 
Steven Taschuk                          staschuk at telusplanet.net
"Its force is immeasurable.  Even Computer cannot determine it."
                           -- _Space: 1999_ episode "Black Sun"





More information about the Python-list mailing list