
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.54 KB | hits: 11 | expires: Never
# see also https://gist.github.com/1093323
class Foo(object):
baz = 15
def deco(f):
'''an in-class decorator method'''
def fun(self, *args, **kwargs):
'''use python generic reference to arguments and implicit self'''
print "before. baz is %s" % self.baz
try:
return f(self, *args, **kwargs)
finally:
print "after. baz is %s" % self.baz
return fun
@deco
def bar(self):
print "in bar, mutating baz"
self.baz = self.baz * 2
Foo().bar()