发布 python-message,一个面向消息编程的程序库

来源:互联网 发布:平板淘宝卖家中心在哪 编辑:程序博客网 时间:2024/06/06 05:44

赖勇浩(http://laiyonghao.com)

前段时间,我发过一篇文章(见:http://blog.csdn.net/lanphaday/archive/2010/11/29/6043605.aspx ),讲了几个我希望能够在 Python 看到的几个特性,其中第三个 message-oriented programming 是很容易实现的,所以我就尝试着把它做出来了,今天在这里公布一下。

pypi:http://pypi.python.org/pypi/message

源代码:http://code.google.com/p/python-message/

现在可以非常简单地安装,只要在命令行执行以下命令就可以了:

easy_install message  

 http://blog.csdn.net/gzlaiyonghao/article/details/6065896

然后来个简单的示例代码:

import messagedef hello(name):  print 'hello, %s.'%namemessage.sub('greet', hello)message.pub('greet', 'lai')

输出:

hello, lai.  

就像所有的 publish/subscribe 模型一样,这个 message module 的作用就是解耦。与常见的 signal/slot 或 observer pattern 不同,它不需要知道谁会发出一条消息(当然,也可以知道),所以可以说是 observer pattern 的一个超集。

为什么设计成这样?嗯,受到 falcon 语言的影响颇大。

这样有什么好处?嗯,容我日后再写文章禀报吧。

http://blog.csdn.net/gzlaiyonghao/article/details/6065896
原创粉丝点击