|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import time as t
class Mytimer():
def start(self):
self.start=t.localtime()
print('开始计时')
def stop(self):
self.stop=t.localtime()
print("停止计时")
self._clac()
def _clac(self):
self.lasting=[]
self.prompting='总共运行了'
for a in range(0,6):
self.lasting.append(self.stop[a]-self.start[a])
self.prompting+=str(self.lasting[a])
print(self.prompting)
执行时出了问题
>>> t1=Mytimer()
>>> t1.start()
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
t1.start()
File "E:/Mytimer.py", line 4, in start
self.start=t.localtime()
AttributeError: type object 'Mytimer' has no attribute 'localtime'
我这可以用,重新执行一遍,应该就好了,
用localtime的话,可能会出现负值,需要考虑进位的问题.
比如1分30秒开始,到2分10秒结束,结果就会是1分-20秒.
还有,建议把属性和方法的名字区别开,同名会覆盖,再运行就报错了.
|
|