SHARE
TWEET

Untitled

a guest Jun 16th, 2017 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. """
RAW Paste Data
Want to get better at Python?
Learn to code Python in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top