import mytimer
import module1
mytimer.stop(msg="Timer from module1:")
# restart timer
mytimer.start()
# .. do something here
# and then get timer with specific message
mytimer.stop(msg='Finished at')
这将导致:
$ python module2.py
Timer from module1 3.81469726562e-06 sec
Finished at 9.53674316406e-07 sec
一个想法是用一个全局变量创建一个模块,这样就不会对名称空间造成太大的污染。你知道吗
这里是我的计时器.py地址:
然后,假设您在module1.py中启动计时器:
当您在另一个模块中调用
mytimer.stop()
时,您可以看到它花了多少时间,下面是module2.py:这将导致:
相关问题 更多 >
编程相关推荐