Created
May 6, 2009 06:31
-
-
Save k0001/107392 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
>>> class A(object): | |
... @classmethod | |
... def magic(cls, fn): | |
... def _f(*args, **kwargs): | |
... print "Hello from", cls, "_f", args, kwargs | |
... return fn(*args, **kwargs) | |
... return _f | |
... | |
>>> class B(object): | |
... @A.magic | |
... def foo(self, a, b, c): | |
... return a + b + c | |
... | |
>>> b = B() | |
>>> b.foo(1, 3, c=5) | |
Hello from <class '__main__.A'> _f (<__main__.B object at 0x17872d0>, 1, 3) {'c': 5} | |
9 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment