python
文章平均质量分 53
luan_tianjiao
这个作者很懒,什么都没留下…
展开
-
python Queue
#coding = utf-8class Node(object): def __init__(self,data=0,next=None): self.data = data self.next = nextclass LinkQueue(object): def __init__(self): self.front = None self.rear = None原创 2015-09-09 16:24:31 · 608 阅读 · 0 评论 -
thread 4, queue
Queue队列LifoQueue后入先出(LIFO)队列PriorityQueue 优先队列原创 2014-01-12 15:07:44 · 560 阅读 · 0 评论 -
python 函数封装
主要是利用globals()下面先简单介绍globals() 和 locals()原创 2014-07-16 15:16:59 · 2322 阅读 · 0 评论 -
python dir & vars
dir 打印出当前模块的所有属性vars打印出当前模块的所有属性以及属性的值原创 2014-04-11 16:13:56 · 766 阅读 · 0 评论 -
sched 定时执行命令
关于定时执行命令,在linux中有crontab简单易用但是想要在python这个粒度下做的话,当然可以利用一个死循环来做import osimport timedef test(): while True: now = time.strftime('%H:%M') print now if '12:00'<now<'13:00原创 2014-03-20 16:25:35 · 1219 阅读 · 0 评论 -
python,os中的文件操作
1.os.walk(root,topdown=True,onerror=None)返回:root,dirs,filesroot为当前处理路径,dirs为root下的文件夹,files为root下的文件a = os.walk(‘.’) for i in a:print i 输出:(‘.’, ['abc', 'temp'], ['path0704.py', '\xc原创 2013-12-11 21:40:03 · 636 阅读 · 0 评论 -
python 打包
当前的包管理工具链是 easy_install/pip + distribute/setuptools + distutils, 显得较为混乱。简介:1.自己编写程序打包工具distutils : Python 自带的基本安装工具, 适用于非常简单的应用场景; 使用方法:为项目创建 setup.py 脚本执行 setup.py install 可进行安装setupt原创 2014-03-14 11:38:10 · 551 阅读 · 0 评论 -
python 异常
以操作文件为例,讲解python异常finally语句cleanup操作,finally无论是否发生except必执行 def divide(x, y): try: result = x / y except ZeroDivisionError: print "division by zero!" else: print "result is", resu原创 2014-01-11 16:23:51 · 531 阅读 · 0 评论 -
virtualenv
简介:正如一台虚拟机允许同时运行多个操作系统一样,virtualenv 也支持您同时运行多个 Python 环境。virtualenv保证了python环境的纯洁性原创 2014-03-14 19:06:25 · 411 阅读 · 0 评论 -
pyflakes
安装:安装pyflakes的时候出现如下问题:Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] ImportError: No module named sitegoog原创 2014-03-14 15:01:32 · 3823 阅读 · 0 评论 -
一个正则表达式引起的杂谈
re.compile(r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')一开始咋也不能明白啥意思探索第一步:(.*?)非贪婪模式的正则匹配 http://blog.csdn.net/lxcnn/article/details/4756030此博客介绍的非常好(?s)正则 (?i,m,s,x,g)正则i,s,m,g这些是模式原创 2014-03-12 10:52:07 · 412 阅读 · 0 评论 -
python Template
from string import Templates = '$who likes $what' t = Template(s) d = {'who': 'jianpx', 'what': 'mac'} print t.substitute(d) 默认的分隔符是 $, 想要换掉这个分隔符的话,只需要继承Template类,然后更改其中的delimiter属性即可#!/us原创 2014-03-12 15:59:17 · 684 阅读 · 0 评论 -
pythonmetaclass
在python中,万事皆对象;因此类也是一个对象,如果类是一个对象,则可以1.将类赋值给一个变量2.copy一个类3.设置属性4.作为参数传递元类,即一个可以创建类的类type就是一个元类,它可以创建类,type创建类的方式type(name of the class, tuple of the parent class (for inheritance, can be原创 2014-03-12 22:02:44 · 517 阅读 · 0 评论 -
python xml
xml简介1.xml文档由起始和结束标签(tag)分割的若干个元素(element)组成2.文档的第一个元素为根元素(root)3.元素中可以有属性(attribute),是名字-值(name-value)对。4.元素可以有具体内容(text),如果没有内容则为空元素,可以用表示5.为了避免命名冲突,可以使用xmlns:prefix声明来定义一个命名空间并取名为prefix原创 2014-03-12 15:15:22 · 490 阅读 · 0 评论 -
re
详细参考:http://wiki.ubuntu.org.cn/Python%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%93%8D%E4%BD%9C%E6%8C%87%E5%8D%97正则表达式是一种小型、高度专业化的编程语言,它内嵌在Python的re模块中,制定规则匹配相应的字符串,简单灵活强大。核心:1.字符匹配:原创 2013-12-11 21:49:30 · 570 阅读 · 0 评论 -
to be continued
第1周 解释型脚本语言初探第2周 python开发环境第 3 周 python使用基础第 4周 python的内置容器之要点,Map & Reduce的使用第 5周 并行开发 fork & thread第6 周 python的正则是什么样的第 7周 socket 编程之基础第 8 周 实现一个抓取代理服务器的小爬虫第 9 周原创 2014-06-19 18:41:52 · 374 阅读 · 0 评论 -
GIL学习
http://zhuoqiang.me/python-thread-gil-and-ctypes.html原创 2014-06-19 18:40:57 · 388 阅读 · 0 评论 -
simplejson json
问题和目的:环境python2.7python2.7的json版本中如果出现中文的话,一直会报错这时候换了使用simplejson就好了使用方法:#几个主要函数:dump、dumps、load、loads,带s跟不带s的区别: 带s的是对 字符串的处理,而不带 s的是对文件对像的处理。json、simplejson效率比较:simplejson在效率上来得有优势,推荐用si原创 2015-09-09 15:12:54 · 786 阅读 · 0 评论 -
排序
http://wuchong.me/blog/2014/02/09/algorithm-sort-summary/原创 2015-09-02 17:01:54 · 341 阅读 · 0 评论 -
设计模式
http://www.cnblogs.com/wuyuegb2312/archive/2013/04/09/3008320.html原创 2015-09-02 17:02:18 · 427 阅读 · 0 评论 -
二叉树
#coding=utf8from collections import dequeclass TreeNode: def __init__(self,left=None,right=None,data=0): self.left = left self.right = right self.data = dataclass Tree原创 2015-09-02 16:43:11 · 277 阅读 · 0 评论 -
python资源帖
python code search enginehttp://nullege.com/原创 2014-03-29 16:36:28 · 490 阅读 · 0 评论 -
py in
1.数据结构dict set 区别 list tuple区别2.else语句3.常用的python库原创 2015-01-20 14:00:28 · 368 阅读 · 0 评论 -
编码方式
1.ASCII码:美国制定了一套字符编码,对英语字符和二进制位之间做了统一规定,被称为ASCII码,0-127共128个字符。非英语国家的字符可以利用剩余的128-255进行编码,即不同语言的128-255段不是同的。不足之处:但是这还是无法满足一些国家的文字,如汉字,多大10万左右,由此而引入了unicode编码方式。2.unicode: Unicode的学名是"Univ原创 2013-12-11 20:59:55 · 562 阅读 · 0 评论 -
python 数据结构
1.dicthas_key 返回true or falsenot in 返回bool类型2.listto be continued原创 2013-12-22 18:21:09 · 778 阅读 · 0 评论 -
python 字典
1.dictdict的key类型不可变,如string,int,tuple,但是list等不可以作为key类型例子import typesdef slicetype(tt): if type(tt) is types.TupleType or type(tt) is types.ListType: return True else:原创 2014-01-11 17:10:55 · 450 阅读 · 0 评论 -
else语句
1.if elseso easy~2.elif分支3.for else / while else求最大约数def showMaxFactor(num): count=num/2 while count>1: if num%count==0: print "largest factor of %d is原创 2015-01-20 14:20:57 · 407 阅读 · 0 评论 -
unittest
python自动单元测试框架 unittest :http://www.ibm.com/developerworks/cn/linux/l-pyunit/类似于Java的Junit,Python语言的开发人员可以使用Steve Purcell编写的PyUnit作为单元测试框架,使得Python程序猿更加容易地增加、管理和执行测试用例,并对测试结果进行分析。uni原创 2013-12-12 18:01:45 · 615 阅读 · 0 评论 -
python 2.7.x 和 3.x 版本区别
http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/key_differences_between_python_2_and_3.ipynbKey differences between Python 2.7.x and Python 3.x转载 2014-12-04 10:38:20 · 1101 阅读 · 0 评论 -
python subprocess
首先python进程中,如果需要调用其他的程序,比如bash等,有以下两种情况1.主程序需要等待被调用程序执行结束,并且需要返回信息等,使用以下方法import subprocesscmd = "xterm -hold -e scipt.sh"# no block, it start a sub process.p = subprocess.Popen(cmd , shell=Tr原创 2014-11-28 16:57:44 · 454 阅读 · 0 评论 -
python资源 covering
http://blog.jobbole.com/74844/原创 2014-08-11 14:52:50 · 343 阅读 · 0 评论 -
python 多线程处理抓取网页
基础知识:queue1.q.task_done(),每次从queue中get一个数据之后,当处理好相关问题,最后调用该方法,主要与q.join配合使用,以提示q.join是否停止阻塞;2.q.join(),阻塞,直到queue中的数据均被删除或者处理。为队列中的每一项都调用一次。thread1.join方法,如果一个线程或者一个函数在执行过程中要调用另外一个线程,并且待到其原创 2013-12-29 01:14:43 · 787 阅读 · 0 评论 -
thread 3, 数据共享
1.Lock2.RLock3.Condition4.Event5.Semaphore具体解释以后添加原创 2014-01-12 14:50:00 · 426 阅读 · 0 评论 -
python 格式化时间字符串
Python格式化日期时间的函数为datetime.datetime.strftime();由字符串转为日期型的函数为:datetime.datetime.strptime(),两个函数都涉及日期时间的格式化字符串,列举如下:%a Abbreviated weekday name%A Full weekday name%b Abbreviated month原创 2014-01-04 14:39:21 · 572 阅读 · 0 评论 -
python MQ
1.RabbitMQ+Pyhtonhttp://www.searchsoa.com.cn/showcontent_43337.htmhttp://www.searchsoa.com.cn/showcontent_43338.htm原创 2014-01-01 15:50:13 · 586 阅读 · 0 评论 -
python 模块简介
常用的外部类库:图形界面1.Tkinter————Python默认的图形界面接口。2.Pmw(Python megawidgets)————Python超级GUI组件集.3.PyGTK ———— 用于python GUI程序开发的GTK+库。4.PyQt ———— 用于python的Qt开发库。5.wxPython ———— GUI编程框架,熟悉MFC的原创 2013-12-28 19:21:23 · 692 阅读 · 0 评论 -
python tricks/tips
http://blog.sae.sina.com.cn/archives/19661.counter使用>>> from collections import Counter >>> c = Counter('hello world') >>> cCounter({'l': 3, 'o': 2, ' ': 1, 'e': 1, 'd': 1, 'h': 1, 'r': 1原创 2013-12-08 17:29:34 · 551 阅读 · 0 评论 -
python email
email简单介绍SMTP协议只能用来发送邮件,默认端口号为25POP3 (Post Office Protocol) &IMAP (Internet Message Access Protocol)POP协议和IMAP协议是用于邮件接收的最常见的两种协议,POP3协议的默认TCP端口号是110,IMAP协议的默认TCP端口号是143MIME (Multipurpose I转载 2013-12-28 20:35:12 · 573 阅读 · 0 评论 -
python 数据库
http://blog.csdn.net/ithomer/article/details/8911468mysqlmysql安装下载 MySQL for Python,最新版 MySQL-python-1.2.4b4.tar.gz1) 提前安装:mysql_config 环境否则后面 python setup.py build 会提示找不到 “Environme原创 2013-12-28 20:03:58 · 485 阅读 · 0 评论 -
根据概率选择函数
首先,将函数名称和概率封装在另一个函数AddAction中进行调用将随机调用函数封装在一个类中 class ProbManager下面详细介绍封装函数AddAction设置全局变量g_funcAndParamMap={}keyword is the function name & value is a list of the probobility and *paramet原创 2013-12-15 18:00:30 · 764 阅读 · 0 评论