Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # decorator
- # -------------
- # normal example
- # ------------------
- # def sqr(i):
- # return i * i
- # def calc(calcFun, numArr):
- # result = []
- # for i in numArr:
- # result.append(calcFun(i))
- # return result
- # numbers = calc(sqr, [1, 2, 3, 4, 5])
- # print(numbers)
- # original decorator example
- # --------------------------------------------
- def decorator_xmple(main_fun):
- def wrapper(*args, **kargs):
- print('this is printed before {} function'.format(main_fun.__name__))
- return main_fun(*args, **kargs)
- return wrapper
- @decorator_xmple
- def msg():
- print('now i got it .. . . . . ')
- msg()
- @decorator_xmple
- def person(name, age):
- print('name & age is: {} , {}'.format(name, age))
- person('riju', 21)
- # passThrough = decorator_xmple(msg)
- # print(passThrough)
Advertisement
Add Comment
Please, Sign In to add comment