psychotrip

Декоратор

May 4th, 2021 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. # Пример декоратора для определения времени работы функции
  2. import time
  3. def decorator_time (func):
  4.  def wrapper_for_func ():
  5.  print ("")
  6.  t = time.time ()
  7.  x = func ()
  8.  dt = time.time () - t
  9.  print (f"Время исполнения функции {func.__name__} равно {dt}")
  10.  return x
  11.  return wrapper_for_func
  12. @decorator_time
  13. def add ():
  14.  i = 0.0
  15.  for i in range (10000):
  16.  i=i+i
  17.  return i
  18. print (add ())
Add Comment
Please, Sign In to add comment