|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下,在pycharm上运行
- import time as t
- class Timer:
- 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)
- t = Timer()
- t.start()
复制代码
会爆出访问未知属性的错误,请问是为什么?不是已经引入时间模块了吗?
- Traceback (most recent call last):
- File "/Users/williamwang/PycharmProjects/类和对象/venv/test1.py", line 24, in <module>
- t.start()
- File "/Users/williamwang/PycharmProjects/类和对象/venv/test1.py", line 6, in start
- self.start = t.localtime()
- AttributeError: 'Timer' object has no attribute 'localtime'
复制代码
a = Timer()
a.start()
不要用t,你已经用了时间模块,重复没搞混吗
|
|