学以致用

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

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
上一页 1 2 3 4 5 6 7 8 ··· 17 下一页

2013年8月27日

摘要: 使用python生成或者解析xml的方法用的最多的可能就数python标准库xml.etree.ElementTree和lxml了,在某些环境下使用xml.etree.ElementTree更方便一些,毕竟是python2.5以后的标准库。没想到的是python标准库中竟然存在这么一个低级的bug,简单来说就是某种情况下使用ElementTree序列化的xml数据竟然无法正常解析。仔细分析之后发现是因为charset的原因,但为何不在序列化的时候就做一些检测,进行相应提醒呢?也不至于出现自己序列化自己却不能正常解析的尴尬局面了吧?这点和lxml相比就差远了。具体示例如下:def test_lx 阅读全文
posted @ 2013-08-27 16:08 Jerry.Kwan 阅读(978) 评论(0) 推荐(0) 编辑

2013年8月21日

摘要: python的Requests(http://docs.python-requests.org/en/latest/)库在处理http/https请求时还是比较方便的,应用也比较广泛。但其在处理response时有一些地方需要特别注意,简单来说就是Response对象的content方法和text方法的区别,具体代码如下:@property def content(self): """Content of the response, in bytes.""" if self._content is False: # Read the 阅读全文
posted @ 2013-08-21 15:21 Jerry.Kwan 阅读(5330) 评论(0) 推荐(0) 编辑

2013年8月7日

摘要: javascript中并没有原生sleep函数可供调用,一般来说为了实现sleep功能,大都是采用SetTimeout来模拟,以下片段采用jquery的delay方法来模拟,也算是提供了另外一个视角吧delay demoRun</html参考资料:http://api.jquery.com/queue/#queue-queueName-callback-next-http://api.jquery.com/jQuery.queue/http://blog.project-sierra.de/archives/1559 阅读全文
posted @ 2013-08-07 13:14 Jerry.Kwan 阅读(6052) 评论(0) 推荐(0) 编辑

2013年7月24日

摘要: 在使用python的json模块对json字串反序列化成python对象的时候出现的字符串都是unicode类型,而不是python内置的str类型。在某种使用场景下用户必须做显式的转换才能正常使用,徒增一些麻烦,为解决这一问题封装下述函数。def convert(input): if isinstance(input, dict): return {convert(key): convert(value) for key, value in input.iteritems()} elif isinstance(input, list): return ... 阅读全文
posted @ 2013-07-24 10:03 Jerry.Kwan 阅读(4468) 评论(0) 推荐(0) 编辑

2013年6月20日

摘要: 以下代码仅作为参考之用select md5, crc32, record->'UserModerAnalysis'->'base_info'->'file_malware' as file_malwarefrom reportsCREATE OR REPLACE FUNCTION py_get_file_malware(record TEXT) RETURNS TEXTAS $$ # pl/python functioin body import json plpy.notice('type of record is&# 阅读全文
posted @ 2013-06-20 10:37 Jerry.Kwan 阅读(4076) 评论(0) 推荐(0) 编辑

2013年6月18日

摘要: 在使用createlang 安装plpythonu的时候出现如下错误:could not open extension control file "/usr/share/postgresql/9.1/extension/plpythonu.control": No such file or directory主要原因是安装postgresql的时候没有使用--with-python选项编译好PL/Python对于已经安装好的postgresql可以通过以下方式解决缺少依赖包的问题:sudo apt-get install postgresql-plpython安装好post 阅读全文
posted @ 2013-06-18 10:43 Jerry.Kwan 阅读(4494) 评论(0) 推荐(0) 编辑

2013年5月27日

摘要: 在做搜索服务的时候,拼写检查应该算是一个锦上添花的功能点,相信大家都还对google的Did you mean:XXX印象深刻,这个是怎么实现的呢?在使用sphinx搜索引擎的时候又能怎么做呢?转载网上的两篇文章:http://norvig.com/spell-correct.htmlhttp://sphinxsearch.com/forum/view.html?id=3709 阅读全文
posted @ 2013-05-27 15:04 Jerry.Kwan 阅读(234) 评论(0) 推荐(0) 编辑

2013年4月3日

摘要: 将使用cx_freeze打包的python程序copy到别的机器上运行时碰到这样的错误:jerrykwan@jerrykwan:~/Downloads/exe.linux-x86_64-2.7$ ./server_family_info Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module> File "server_family_info 阅读全文
posted @ 2013-04-03 16:42 Jerry.Kwan 阅读(16928) 评论(0) 推荐(1) 编辑

2013年3月21日

摘要: 在使用cx_freeze将python程序转换成exe的时候碰到如下错误:setup.py内容如下:import sysfrom cx_Freeze import setup, Executable# Dependencies are automatically detected, but it might need fine tuning.build_exe_options = { # "packages": ["os"], "include-files": ["security/cert.pem"... 阅读全文
posted @ 2013-03-21 16:26 Jerry.Kwan 阅读(2225) 评论(0) 推荐(0) 编辑

2013年3月20日

摘要: 在linux下使用ipython的pylab模式时发现使用matplotlib绘制的图形并未之直接显示出来,而且程序也没有出现任何的错误提示,很是奇怪google之后发现原始来matplot配置信息的问题,通过调整matplotlibrc中的backend配置就可以轻松解决这一问题,解决方案如下:(1)找出matplotlibrc的具体问题 In [4]: import matplotlib In [5]: matplotlib.matplotlib_fname() Out[5]: '/usr/local/lib/python2.7/dist-packages/matplotlib/m 阅读全文
posted @ 2013-03-20 09:51 Jerry.Kwan 阅读(1409) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 17 下一页