Decorator in Python
Decorator Simple Examples
import time
def hello(name):
print("Hello, my name is " + name)
def track_time(func):
def new_func(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
end_time = time.time()
print(f"Execute Time : {end_time - start_time}")
return new_func
hello = track_time(hello)
hello("primrose")
# ##
# νμ₯μ±μ μν΄ track_timeμ΄λΌλ λ°μ½λ μ΄ν° ν¨μλ₯Ό λ§λ λ€. μΈμλ‘ ν¨μλ₯Ό λ°κ³ , λ΄λΆμ ν¨μλ₯Ό 리ν΄ν΄μ€λ€.
# 리ν΄λλ ν¨μλ λ°μ½λ μ΄ν° ν¨μ μμμ μ μλ ν¨μμ΄κ³ , νμ₯μ±μ μν΄ packingνλ€.
"""
Hello, my name is primrose
Execute Time : 2.193450927734375e-05
"""Last updated