Skip to content

Instantly share code, notes, and snippets.

@qingfeng
Created August 12, 2011 07:05
Show Gist options
  • Save qingfeng/1141617 to your computer and use it in GitHub Desktop.
Save qingfeng/1141617 to your computer and use it in GitHub Desktop.
Decorator by class
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