python类里面使用装饰器

参考:http://m.blog.csdn.net/blog/wklken/8118942


def on(name, *args_of_on, **kwargs_of_on):
def handle_func(func):
def handle_func_args(self, *args_of_func, **kwargs_of_func):
print "see args_of_on:", name, args_of_on, kwargs_of_on
print "see args_of_func:", self, args_of_func, kwargs_of_func

func(self, *args_of_func, **kwargs_of_func)
# if getattr(self, "on_"+name, False):
# getattr(self, "on_"+name)(args)
return handle_func_args
return handle_func


class XX(object):
# def on_tick(self, *args):
# print self, *args

@on("tick", 123)
def on_data(self, xx):
print "see in on_data:", self, xx


a = XX()
print a
a.on_data(55)
posted @ 2015-12-31 15:02  小鼬就是我  阅读(1221)  评论(0编辑  收藏  举报