Advertisement
here2share

# b_decorator.py

Oct 19th, 2021
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # b_decorator.py
  2.  
  3. def mydecorator(decorated_func):
  4.     def wrapped(*args, **kwargs):
  5.         print("In decorator!")
  6.         return decorated_func(*args, **kwargs)
  7.     return wrapped
  8.  
  9. @mydecorator
  10. def myfunc(myarg):
  11.     print("In decorated myfunc function", myarg)
  12.    
  13. def my2nd_func(myarg):
  14.     print("In my2nd_func function", myarg)
  15.  
  16. myfunc('global string')
  17. my2nd_func('my2nd_func without decorator')
  18. my2nd_func = mydecorator(my2nd_func)
  19. my2nd_func('my2nd_func with decorator added')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement