New Time format
Cliff Wells
logiplexsoftware at earthlink.net
Fri Jan 25 14:56:41 EST 2002
On Thu, 24 Jan 2002 23:56:35 +0000
Dale Strickland-Clark wrote:
> Martin von Loewis <loewis at informatik.hu-berlin.de> wrote:
> The problem is I have to look it up EVERY time I use it. It's too
> fussy for the simple case where I want a basic date/time.
>
> >I'd question that people can memorize the meaning of a number in 0..4
> >to identitify a format much better than they can memoryize strftime
> >format specifiers. I'm pretty sure that people can *read*
>
> But I can find a number between 0..4 by trial and error in a few
> moments.
Why not make a module isotime.py:
import time
class __isotime:
def __init__(self):
self.isotime = [
"%H:%M:%S",
"%Y-%m-%d",
"%Y-%b-%S",
"%Y-%m-%d %H:%M:%S",
"%Y-%b-%d %H:%M:%S",
]
def __call__(self, thetime, format):
return time.strftime(self.isotime[format], thetime)
isotime = __isotime()
Then you can reuse that wherever you like:
>>> from isotime import isotime
>>> import time
>>> t = time.localtime(time.time())
>>> print isotime(t, 0)
11:55:09
>>>
Does this basically do what you want? Personally, I don't have a problem
with the existing library, but to each his own.
--
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308
More information about the Python-list
mailing list