Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. from functools import wraps
  2.  
  3. class Formatter(object):
  4. def cap(self):
  5. def cap_decorator(func):
  6. @wraps(func)
  7. def func_wrapper(value):
  8. return func(value).upper()
  9. return func_wrapper
  10. return cap_decorator
  11.  
  12. formatter = Formatter()
  13.  
  14. class Person(object):
  15.  
  16. def __init__(self, name):
  17. self.name = name
  18.  
  19. @formatter.cap()
  20. def sayHi(self):
  21. return self.name
  22.  
  23. bob = Person('Bob')
  24. print bob.sayHi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement