随笔分类 -  python

摘要:在php中可以很方便的通过array_chunk 进行大数组的切割操作,但是在python中目前貌似没有可以直接使用的方法,下面是在网上搜索了一番,找到一个不错的解决办法,是利用python的生成器(yield)方法实现。具体的代码如下:def iterator_chunk(iterator, size, strict=False): rt = [] for it in iterator: rt.append(it) if len(rt) == size: yield tuple(rt) rt = [] ... 阅读全文
posted @ 2013-03-04 11:42 涛光 阅读(640) 评论(0) 推荐(0) 编辑
摘要:在安装 mysql-python时,会出现:sh: mysql_config: not foundTraceback (most recent call last): File "setup.py", line 15, in <module> metadata, options = get_config() File "/home/zhxia/apps/source/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config libs = mysql_config("libs 阅读全文
posted @ 2012-12-12 11:31 涛光 阅读(78341) 评论(3) 推荐(7) 编辑
摘要:python下实现多线程有两种方式:一种是通过函数的方式产生新的线程,另外一种是通过面向对象的方式实现通过调用thread模块中的start_new_thread()函数来产生新线程#!/usr/bin/env python#encoding:utf-8#author:zhxiaimport threadimport timethread_count=0;def test(num,interval): for x in xrange(1,10): print 'current thread is:%d,and x is:%d'%(num,x) ... 阅读全文
posted @ 2012-12-11 13:12 涛光 阅读(605) 评论(0) 推荐(0) 编辑
摘要:在python中,全局变量一般有两种使用方式:第一种:是在一个单独的模块中定义好,然后在需要使用的全局模块中将定义的全局变量模块导入。第二种:直接在当前的模块中定义好,然后直接在本模块中通过global声明,然后使用具体的方法如下所示:第一种:SOLR_URL='http://solr.org'def tt(): global SOLR_URL SOLR_URL=SOLR_URL+'#aa'if __name__=='__main__': tt() print SOLR_URL#输出:http://solr.org#aaPS:在此种用法中,如果我 阅读全文
posted @ 2012-12-11 13:11 涛光 阅读(125598) 评论(3) 推荐(2) 编辑
摘要:shell:#!/bin/bash#==========================================================# this example show you how to get data from pipe#========================... 阅读全文
posted @ 2012-11-13 09:27 涛光 阅读(269) 评论(0) 推荐(0) 编辑