Created
August 12, 2011 07:05
-
-
Save qingfeng/1141617 to your computer and use it in GitHub Desktop.
Decorator by class
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 d(object): | |
def __init__(self,x,y): | |
self.x = x | |
self.y = y | |
def __call__(self, func): | |
def _(*args): | |
self.x *= 2 | |
self.y *= 2 | |
v = self.x+self.y+args[0] | |
return func(v) | |
return _ | |
@d(x=1,y=2) | |
def abc(z): | |
print "z",z | |
abc(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment