学以致用

focus on Python , C++, and some interest in Go and R

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页

2012年3月28日

摘要: 推荐一个Continuous Integration and Code Review工具组合Jenkins,一个采用java语言编写的持续集成工具,用户众多,而且有各种各样的plugin可供使用Gerrit,一个代码审查工具,对于采用git作为源码管理的项目来说非常适合 阅读全文
posted @ 2012-03-28 10:27 Jerry.Kwan 阅读(227) 评论(0) 推荐(0) 编辑

2012年3月26日

摘要: A Guide to Python's Magic Methods主要包括一些 attributeaccess,reflection, context manager,pickling等转载自 http://www.rafekettler.com/magicmethods.html 阅读全文
posted @ 2012-03-26 11:34 Jerry.Kwan 阅读(257) 评论(0) 推荐(0) 编辑

摘要: 最近在做一个权限系统,期望的效果如下:权限部分是一个二级结构, contenttype.action假定对外暴露的接口为 perms 变量,期望能通过 if perms.contentname 来判断用户是否拥有contentname中的任一action的权限,通过 if perms.contentname.actionname来判断用户是否具有contentname下的actionname权限。为了方便用户使用,决定使用python的操作符重载。具体代码如下:class PermLookupDict(object): def __init__(self, datas, content_... 阅读全文
posted @ 2012-03-26 11:31 Jerry.Kwan 阅读(469) 评论(0) 推荐(0) 编辑

2012年3月22日

摘要: 常见的一个问题就是如何向PySide/PyQt的slot中传递额外的参数。slot的机理就是将signal和slot建立关联,signal的参数能够传递到slot中,但额外的参数(用户自定义的)并不能直接传递进去。但现实中传递用户自定义的参数还是很有意义的,这样一来用户就可以定义一个slot来处理多个signals,只是通过参数来区分即可。如果实现呢?一个简单的方法就是借助于lambda,下面是一个简单的例子:self.configInqAct = QtGui.QAction("Inquiry", self)self.configInqAct.setStatusTip(&q 阅读全文
posted @ 2012-03-22 16:04 Jerry.Kwan 阅读(1469) 评论(0) 推荐(0) 编辑

2012年3月8日

摘要: 在通过python setup.py install 安装gevent后,使用gevent时提示如下错误:# python2.6Python 2.6.7 (r267:88850, Sep 6 2011, 08:13:16) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import geventTra 阅读全文
posted @ 2012-03-08 14:01 Jerry.Kwan 阅读(1778) 评论(1) 推荐(0) 编辑

2012年3月6日

摘要: 在使用web.py进行开发的时候避免不了会在template中使用$code来定义一些小函数,按照web.py的文档来看,$code之内能包含任意的python代码,但在实际使用的时候却经常发现不是这个样子的,只有特定的函数可以在$code中出现,比如说默认情况下在template中可以使用 len 函数,但却不能使用 str,为什么?仔细分析web.py的源码可以发下:所有有关template处理的都包含在template.py文件中。调用template最终会调用到BaseTemplate 的_compile方法,其中_compile的实现细节为def _compile(self, cod 阅读全文
posted @ 2012-03-06 14:17 Jerry.Kwan 阅读(992) 评论(0) 推荐(0) 编辑

2012年3月2日

摘要: 在webpy的整个framework中,我觉得最不合理也最失败的就属这个web.database的封装了。就我本人的理解,webpy对database的封装不说应该做到Django或者SQLAlchemy的水平,至少应该保持接口一致吧,但我们的webpy是什么样子呢?举个简单的例子,初始化一个database:对于sqlite是这样的:db = web.database(dbn = "sqlite", db = "./db.sqlite")但对于postgresql却是另外一个样子:db = web.database(dbn='postgres& 阅读全文
posted @ 2012-03-02 17:01 Jerry.Kwan 阅读(1880) 评论(1) 推荐(0) 编辑

摘要: 在使用webpy的session时经常会发现按照文档是说明构造的session用法却总是出错,和预想差异很大。通过跟踪webpy源码发现原来默认情况下webpy在session这块儿做了很多手脚。举例如下:(1)session不能在debug模式中使用(2)session不能在webpy内置的wsgi server中使用究其原因是因为webpy在debug或者内置wsgi server中使用的时候启用了模块级的reload,reloader 加载了主模块零次,一次是作为__main__被加载,一次是作为真正的文件被加载,这样就导致了程序中使用的session不是同一个。通过查看webpy源码中 阅读全文
posted @ 2012-03-02 16:27 Jerry.Kwan 阅读(1121) 评论(0) 推荐(0) 编辑

摘要: 在使用webpy时发现的web.application reload的猫腻,暂时记录下来,以便自己和他人参考。现象是这样的: 在配置文件中定义urls:urls = ( # front page "/", "app.controllers.base.index", "/index/", "app.controllers.base.index", ) 同时为了隐藏部分url对应关系,在程序中增加url映射关系如下:self._app.add_mapping(url_login, Login)sel... 阅读全文
posted @ 2012-03-02 16:14 Jerry.Kwan 阅读(1116) 评论(0) 推荐(0) 编辑

2012年2月22日

摘要: Releases will be numbered with the follow format:<major>.<minor>.<patch>And constructed with the following guidelines:Breaking backward compatibility bumps the majorNew additions without breaking backward compatibility bumps the minorBug fixes and misc changes bump the patch 阅读全文
posted @ 2012-02-22 10:35 Jerry.Kwan 阅读(264) 评论(0) 推荐(0) 编辑

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页