DECROMAX

Decorator with argument

Jun 20th, 2022
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. from functools import wraps
  2.  
  3.  
  4. def add_num(num):
  5.     def decorator(func):
  6.         @wraps(func)
  7.         def inner(*args, **kwargs):
  8.  
  9.             add_two = func(*args, **kwargs) + num # call funct with args, kwargs and add number (num) argument
  10.             return add_two
  11.  
  12.         return inner
  13.  
  14.     return decorator
  15.  
  16.  
  17. @add_num(8)
  18. def forty():
  19.     return 40
  20.  
  21.  
  22. print(forty())
Advertisement
Add Comment
Please, Sign In to add comment