马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import time
#def一个函数当计算出的时间列表里面有负数时自动调整为需要的没有负数的数据
def adjust(mylist,index):
date=[0,12,30,24,60,60]
if mylist[index]:
mylist[index]-=1
mylist[index+1]+=date[index]
else:
index-=1
adjust(mylist,index)
class Timer:
def start(self):
self.begin=time.localtime
print('计时开始')
def stop(self):
self.end=time.localtime
self.__calc()
def __calc(self):
unit=['年','月','日','时','分','秒']
self.lasted=''
self.mylist=[]
for index in range(6):
self.mylist.append(self.end[index]-self.begin[index])
for index in range(6):
if self.mylist[index]<0:
index-=1
adjust(mylist,index)
for index in range(6):
if self.mylist[index]:
self.lasted+=str(self.mylist[index])+unit[index]
print('计时结束'+'\n'+'共运行%s'%self.lasted)
t=Timer()
t.start()
t.stop()
self.mylist.append(self.end[index]-self.begin[index])系统报告这行类型错误,函数不可加下标,
大佬们帮我改下程序,让他能跑起来
import time
# def一个函数当计算出的时间列表里面有负数时自动调整为需要的没有负数的数据
def adjust(mylist, index):
date = [0, 12, 30, 24, 60, 60]
if mylist[index]:
mylist[index] -= 1
mylist[index + 1] += date[index]
else:
index -= 1
adjust(mylist, index)
class Timer:
def start(self):
self.begin = time.localtime()
print('计时开始')
def stop(self):
self.end = time.localtime()
self.__calc()
def __calc(self):
unit = ['年', '月', '日', '时', '分', '秒']
self.lasted = ''
self.mylist = []
for index in range(6):
self.mylist.append(self.end[index] - self.begin[index])
for index in range(6):
if self.mylist[index] < 0:
index -= 1
adjust(self.mylist, index)
for index in range(6):
if self.mylist[index]:
self.lasted += str(self.mylist[index]) + unit[index]
print('计时结束' + '\n' + '共运行%s' % self.lasted)
t = Timer()
t.start()
|