#聲明一個修飾符 def mycall(f): def __call__(): print ("==========") return f() return __call__ def timeslong(func): def call(*args, **kwargs): start = time.clock() print("it is time start") func(*args, **kwargs) stop = time.clock() print ("it is time stop") print ("coast time is %s",(stop - start)) return call @mycall @timeslong def function2(): print("this is function2") @mycall @timeslong def function1(): print("this is function1") if __name__=='__main__': function1() function2()
兩個知識點:一是:關於時間的取得,能夠使用time.clock方法來得到python
另外就是如何定義一個函數。函數