Last active
December 18, 2015 11:59
-
-
Save inoshiro/5779548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: def deco(arg): | |
...: def wrapper(func): | |
...: def _wrapper(): | |
...: return func(arg) | |
...: return _wrapper | |
...: return wrapper | |
...: | |
In [2]: @deco("ham") | |
...: def spam(egg): | |
...: print egg | |
...: | |
In [3]: spam() | |
ham |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: def deco(func): | |
...: def wrap(): | |
...: return func | |
...: wrap.hoge = "hoge" | |
...: return wrap | |
...: | |
In [2]: @deco | |
...: def hoge(): | |
...: print hoge.hoge | |
...: | |
In [3]: h = hoge() | |
In [4]: h() | |
hoge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment