Python装饰器这种用法可以吗,Python装饰器用法,class Event(


class Event(object):    def __init__(self):        self.m=[]    def __call__(self,hand):        def hand_w(hand):            return self.__call__(hand)            return hand_w        self.m.append(hand)    def send(self,a):       self.m.hand(a)on_ooo=Event()for k, v in globals().items():    if isinstance(v, Event):        setattr(v, "name", k)@on_ooodef message(self,a):    l=[]    l.append(a)on_ooo.send(4)#这里会调用 message()

具体参考

https://github.com/newlife/django-socketio/blob/master/django_socketio/events.py

2013-11-13修改了格式

拿余光瞟了下,第8行错了,你怎么在 renturn 后去 append 呢?

http://segmentfault.com/q/1010000000309309#a-1020000000309337 这个问题也是你提的吧?我在原来的答案里按你的代码修改了一下

编橙之家文章,

评论关闭