Python装饰器这种用法可以吗,Python装饰器用法,class Event(
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 这个问题也是你提的吧?我在原来的答案里按你的代码修改了一下
编橙之家文章,
相关内容
- Python sdk文档中尖括号如何处理,pythonsdk文档括号,比如
- 为什么读取通过cookielib方法得到的cookies返回值是空的
- 请教Python分布式实现一个helloworld的思路,pythonhellowor
- Python syslog模块怎么判断发送状态,pythonsyslog,syslog服务
- Python class Vector 的创建,pythonvector,创建一个向量的cla
- Python 源码中的re表达式同原生字符是怎么匹配成功的,
- Mac python2.7.3创建虚拟环境提示ImportError: No module named .
- PythonGIL与线程安全问题?,pythongil安全问题,由于一些历
- Pythom Scrapy框架Imagepipeline组件下载gif类型文件处理问题
- 同一个程序在python2.7.3与2.7.2环境运行会出现不同结果吗
评论关闭