rpc框架 SimpleXMLRP
一台电脑去控制另一台电脑干事情,最常见的就是web。
用户get/post一个url,服务端根据url地址和参数去做相应的事情把结果返回给客户端。
server.py
#coding=utf8 from SimpleXMLRPCServer import SimpleXMLRPCServer import time def happy(x): return time.strftime('%H:%M:%S'),"I play Python.! \n x is %s"%x sxr=SimpleXMLRPCServer(("", 8080), allow_none=True) sxr.register_function(happy) sxr.serve_forever()
client.py
#coding=utf8 from xmlrpclib import ServerProxy sp = ServerProxy("http://localhost:8080") print sp.happy('hi') print sp.happy('hello')
运行server.py,运行client.py,client可以和server不在同一个机器,调用另一台机器做事情。
反对极端面向过程编程思维方式,喜欢面向对象和设计模式的解读,喜欢对比极端面向过程编程和oop编程消耗代码代码行数的区别和原因。致力于使用oop和36种设计模式写出最高可复用的框架级代码和使用最少的代码行数完成任务,致力于使用oop和设计模式来使部分代码减少90%行,使绝大部分py文件最低减少50%-80%行的写法。