class Timer def __init__ self import time self time time def start sel

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
>>> class Timer:
def __init__(self):
import time
self.time=time
def start(self):
self.time1=self.time.gmtime(self.time.time())
def stop(self):
self.time2=self.time.gmtime(self.time.time())
def get(self):
t=self.time.mktime(self.time2)-self.time.mktime(self.time1)
s=self.time.strftime('%H:%M:%S',self.time.gmtime(t))
return s
>>> def f():
t=Timer()
t.start()
time.sleep(5)
t.stop()
print t.get()
>>> import time
>>> f()
00:00:05
>>>