Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. >>> def decorator(func):
  2. ...     def wrapper(arg):
  3. ...        return func(arg)
  4. ...     wrapper.__name__ = func.__name__
  5. ...     wrapper.__dict__.update(func.__dict__)
  6. ...     return wrapper
  7. ...
  8. >>> @decorator
  9. ... def foo(arg):
  10. ...     print arg
  11. ...     return arg
  12. ...
  13. >>> foo(1)
  14. 1
  15. 1
  16. >>> foo(1, 2)
  17. Traceback (most recent call last):
  18.   File "<stdin>", line 1, in <module>
  19. TypeError: wrapper() takes exactly 1 argument (2 given)
  20. >>> foo.__name__
  21. 'foo'
  22. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement