|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import time as t
class MyTimer:
#开始计时
def start(self):
self.start = t.localtime()
print("计时开始...")
#停止计时
def stop(self):
self.stop = t.localtime()
print("计时结束!")
#停止计时
def stop(self):
self.stop = t.localtime()
self._calc()
print("计时结束!")
# 内部方法,计算运行时间
def _calc(self):
self.lasted = []
self.prompt = "总共运行了"
for index in range(6):
self.lasted.append(self.stop[index] - self.start[index])
self.prompt += str(self.lasted[index])
print(self.prompt)
请问:
def start(self):
self.start = t.localtime()
这两句的start 属性名和方法名不冲突吗
假如在开始再增加
def __init__(self):
self.prompt = "未开始计时!"
self.lasted = []
self.start = 0
self.stop = 0
运行时候就会提示
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
t1.start()
TypeError: 'int' object is not callable
此时属性名和方法名就冲突了
|
|