一个简单有效的事件处理程序类,基于Python3的回调
eventhandler的Python项目详细描述
事件处理程序
是一个基于python3回调的简单有效的事件处理程序类。在
安装程序包
$ pip install eventhandler
使用示例
让我们看一个由bot使用事件调用控制的聊天室的简单示例。在
您只需将下一个代码保存到一个文件中,然后运行python3来执行它文件名.py在
^{pr2}$avobe代码必须生成并输出以下内容:
Chatroom's EventHandler object representation... <class EventHandler at 0x10da97760: onNewuser:[__on_newuser_join, saludate_new_user], onMessage:[__on_message, read_user_message], verbose=False, tolerate_exceptions=False> ** ChatRoom info ** user sergio has joined the chat ** 1 user/s ** bot says: Hello sergio, welcome to the chat room. sergio says: Hello World! sergio says: Hey bot, are there anyone here? bot says: Nope sergio. Just you and me. ** ChatRoom info ** user david has joined the chat ** 2 user/s ** bot says: Hello david, welcome to the chat room. david says: Hello everybody! david says: Hey bot, are there anyone here? bot says: Yes david. there are 1 non bots users in the room, you, and me. sergio says: Hi david! ** ChatRoom info ** user kate has joined the chat ** 3 user/s ** bot says: Hello kate, welcome to the chat room. kate says: Hey bot, are there anyone here? bot says: Yes kate. there are 2 non bots users in the room, you, and me.
感谢您的收看和欣赏。
由David Vicente Ranz编写、测试和包装
- 项目
标签: