Python question
Steven W. Orr
steveo at syslang.net
Thu Jan 8 22:58:42 EST 2009
On Tuesday, Jan 6th 2009 at 16:26 -0000, quoth Paul Lussier:
=>
=>Hi Folks,
=>
=>Is there a python way to get HH:MM:SS from time.localtime() ?
=>
=>I'm trying to time how long it takes a python script to run and have
=>thus done:
=>
=> BEGIN = time.time()
=> ....
=> END = time.time()
=>
=> ELAPSED = END - BEGIN
=>
=>So, now I have a number like 1231265125.36
=>
=>Which is great, and I can write the code necessary to convert it, but
=>figured that this wheel is probably already invented.
=>
=>And, since I'm just learning python, all better ideas are welcome :)
Think more ooopsier.
#! /usr/bin/python
import datetime
import time
then = datetime.datetime.now()
print "then = ", then
time.sleep(5)
now = datetime.datetime.now()
print "now = ", now
print "Elapsed = ", now - then
datetime.now() returns a datetime object and those objects allow for
various types of artithmetic to be perfomed on them. :-)
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
More information about the gnhlug-discuss
mailing list