|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在看视频的时候按照小甲鱼写的代码,自己敲出来之后却出错了
已经仔细看过了,并没有语法格式上的错误
就是调用开始计时和结束计时,然后计算时间差,实现一个简单的计时器
代码如下
- import time as t
- class MyTimer():
- #开始计时
- def start(self):
- self.start = t.localtime()
- print("计时开始")
- #停止计时
- def stop(self):
- self.stop = t.localtime()
- self._clac()
- 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)
复制代码
调用及错误如下
- >>> tt = MyTimer()
- >>> tt.stop()
- Traceback (most recent call last):
- File "<pyshell#38>", line 1, in <module>
- tt.stop()
- File "D:/Python/fishc_study/45.2.py", line 12, in stop
- self._clac()
- AttributeError: 'MyTimer' object has no attribute '_clac'
- >>>
复制代码
刚开始学python 许多不清楚的地方 还请各位过帮助帮助
|
|