Advertisement
DigitalMag

decorator with parameters to lambda

Jul 5th, 2020
1,565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # from numba import jit
  2.  
  3. def decorator_maker(*arg):
  4.     print('decor args:' + str(arg))
  5.     def my_decorator(func):
  6.         def wrapped(*args, **kwargs):
  7.             print('func arg:' + str(args))
  8.  
  9.             print('start')
  10.             return func(*args)
  11.         return wrapped
  12.     return my_decorator
  13.  
  14.  
  15. @decorator_maker(1)
  16. def decorated_func(a):
  17.     print ('func inside')
  18.  
  19. decorated_lambda = decorator_maker(3)(lambda x: x+1)
  20. # decorated_lambda2 = jit(nopython=True)(lambda x: x+1)
  21.  
  22. if __name__ == '__main__':
  23.     decorated_func(2)
  24.     decorated_lambda(0)
  25.     # decorated_lambda2(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement