Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. class WrapExample(object):
  2.     def __init__(self, arg):
  3.         def _wrapper(self):
  4.             return self.wrapper(self, arg)
  5.         self.wrap_me = _wrapper
  6.  
  7.     def wrap_me(self):
  8.         pass
  9.  
  10.     def wrapper(self, arg):
  11.         print arg
  12.  
  13. def main():
  14.     s = WrapExample('hello')
  15.     s.wrap_me()
  16.  
  17. if __name__ == '__main__':
  18.     main()
  19.  
  20. """
  21. when ran, the program outputs the following exception:
  22.     Traceback (most recent call last):
  23.       File "t.py", line 18, in <module>
  24.         main()
  25.       File "t.py", line 15, in main
  26.         s.wrap_me()
  27.     TypeError: _wrapper() takes exactly 1 argument (0 given)
  28.  
  29. Is there a way to wrap a method ?
  30. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement