Untitled
This snippet demonstrates a decorator 'atualizar' that tracks the execution time of a function by printing the current time before and after the function call. It showcases both its usage with the '@' syntax and as a separate call to illustrate alternative approaches.from datetime import datetime from time import sleep def atualizar(funcao): def horario_de_inicio(): print(datetime.now().strftime('%H:%M:%S')) funcao() print(datetime.now().strftime('%H:%M:%S')) return horario_de_inicio @atualizar # Primeiro modo def tempo(): print('Atualizando...') sleep(1) tempo() # Primeiro modo # pronto = atualizar(tempo) ## Segundo modo # pronto() ## Segundo modo
Leave a Comment