我的博客从来没有废话直接搞起来
import time
class Timer:
def __enter__(self):
self.start_time = time.time()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.end_time = time.time()
self.execution_time = self.end_time - self.start_time
print("代码执行了")
def say_hello(self):
print("大家伙")
if __name__ == '__main__':
with Timer() as timer:
timer.say_hello()