|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
哪位大神可以告诉我为啥总是提示在MyTime里面没有属性calc,以下是代码和运行结果
- import time as t
- class MyTimer():
- #开始计时
- def start(self):
- self.start = 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)
复制代码
====================================== RESTART: C:\Users\john\Desktop\time.py =====================================
>>> t1 = MyTimer()
>>> t1.start()
计时开始...
>>> t1.stop()
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
t1.stop()
File "C:\Users\john\Desktop\time.py", line 12, in stop
self.calc()
AttributeError: 'MyTimer' object has no attribute 'calc'
问题解决了话,就设个最佳把求助帖关了吧,给你回复的几个,都很快就发现了你的代码的问题
|
|