|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在看小甲鱼的第44讲,制作一个计时器,代码如下:
import time as t
class MyTimer():
#开始计时
def start(self):
self.start1 = t.localtime()
print('Timing starts')
#结束计时
def stop(self):
self.stop1 = t.localtime()
self.total()
print('Timing stops')
#计时计算
def total(self):
self.last = []
self.prompt = 'It\'s '
for each in range[6]:
self.last.append(self.stop1[each]-self.start1[each])
self.prompt += str(self.last[each])
print(self.prompt)
运行之后,报错:
>>> t = MyTimer()
>>> t.start()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
t.start()
File "F:\Programming\Python\practice\44.0.py", line 6, in start
self.start1 = t.localtime()
AttributeError: 'MyTimer' object has no attribute 'localtime'
求大佬解答!
对象名和里面的time模块的别名冲突了
- t1 = MyTimer()
- t1.start()
复制代码
|
|