Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # testing decorator functions
- def decorator1(func):
- def inner(value):
- print(value)
- inner.history = []
- inner.history.append(value)
- return inner
- @decorator1
- def test1(value):
- pass
- print("Testing function decorators")
- test1(1)
- test1(2)
- print(test1.history)
- # testing class functions
- class Decorator2(object):
- def __init__(self, func):
- self._func = func
- self.history = []
- def __call__(self, value):
- print(value)
- self.history.append(value)
- @Decorator2
- def test2(value):
- pass
- @Decorator2
- def test3(value):
- pass
- print("Testing class decorators")
- test2(1)
- test2(2)
- test3(3)
- print(test2.history)
- """
- Testing function decorators
- 1
- 2
- [2]
- Testing class decorators
- 1
- 2
- 3
- [1, 2]
- """
Add Comment
Please, Sign In to add comment