Python
文章平均质量分 60
WalleFu
希望做一个思想自由的人, 通过自己的努力给家人提供一个舒适的生活条件,并有能力帮助和影响周围的朋友。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Python 编码规范
每个程序员写代码时有必要遵循自己的一个标准,一个团队要形成共同认知的标准,这一标准可以简单也可以复杂,但需要贯彻。我计划每3个月指定10条编码规范,三个月后,评估这三个月的代码,对每一项打分,对于分数较高的移入备份规则库,较低的继续保留,并且增加新的条目,以保持规范数量不变。2012年12月,编码规范(主要是python语言):1. 用最少的代码原创 2012-12-16 12:37:48 · 718 阅读 · 0 评论 -
Some tips about Class in Python
1. class statementA class is defined using the class statement.The body of a class contains a series of statements that execute during class definition. Here's an example:class A原创 2013-07-24 19:18:17 · 863 阅读 · 0 评论 -
Modules you should know in Python Libray
前两天被问到常用的python lib和module有哪些?最常用的那几个,其他的一下子竟然回答不上。想想也是,一般情况下,遇到一个问题,在网上一搜,顺着线索找到可用的例子,然后基本没有怎么深究。结果就导致了现在没有网络基本写不出代码的状况,搜索是程序员必须的技能,但是只依靠搜索例子是无法成长的。今天抽出1个小时时间把一些重要的module的简要整理出来,逐步一个个熟悉。原创 2013-08-01 17:36:39 · 1514 阅读 · 0 评论 -
Decorator in Python
A decorator is a function whose primary purpose is to wrap another function or class.The primary purpose of this wrapping is to transparently alter or enhance the behavior of the object being wr原创 2013-07-25 22:00:18 · 796 阅读 · 0 评论 -
Python局部变量的一个区别于其他语言的小特性
Python中变量作用域和C/C++和Java有一些不同,下面我们通过一个小例子来说明,类似例子我并没有在任何一本书中看到过,希望对于初学者有帮助。例子分成两小段代码,你可以分别运行,观察if条件内的局部变量temp.(1)data = [2,1,0]for i in data: temp = i if i>0: print "==原创 2014-07-08 16:33:40 · 1288 阅读 · 0 评论 -
Python实现的Observer Pattern
最近因为部门调整,学习时间较多,利用这段时间抽空把Python又拿出来学习一下,借此机会也复习一下设计模式。下面使用Python简单实现如下:原创 2014-07-09 13:45:06 · 2094 阅读 · 0 评论 -
Python: 初识shelve module
看一段开源的Python工具源码,发现采用了shelve这个module来存储数据,而且接口设计的非常好用。这里简单介绍一下。这是python自带的一个非常实用的module,用来进行数据存储非常方便。简单来说,通过在当前或者指定路径建立一个文件来存储字典结构的数据:字典的key是用字符串,value可以使任何数据对象。它与dbm不同的是,字典的值可以是任意的数据对象。原创 2014-08-09 15:05:51 · 1163 阅读 · 0 评论 -
关于编写高质量的Python代码有感
最近在整理新项目在Robot上的模块级测试项目的应用库,真的是感慨芬兰的员工的代码质量真的让国内的人汗颜。设计简洁,代码高效优美,不仅仅为了完成当前的工作,为未来的接口也做了适当的设计。其实一段代码既可以为了完成任务草草完事,也可以精益求精,完全取决于一个程序员是否对自己有要求。记得在之前的测试开发项目组,曾经做过一个脚本开发的统一模板,目的为了更好的提高单个module的质量,同时方原创 2014-08-24 13:01:10 · 1517 阅读 · 0 评论 -
Python: 使用select函数编写nonblocking TCP/IP socket程序
select函数的理解对于灵活运用socket函数编程有直接的影响,我们编写的网络库一般需要支持多连接,因此select提供的特性很好的满足了这一需求。关于select的解释可以参考:select(2) 使用C或者C++编写一个实例程序相对比较麻烦,我们可以直接使用Python快速开发一个 nonblocking TCP/IP socket Demo来看一下select怎么应用到Soc原创 2014-07-08 11:49:06 · 3503 阅读 · 0 评论 -
Python 处理进程等待时间
This class represents an action that should be run only after a certain amount of time has passed — a timer. Timer is a subclass of Thread and as such also functions as an example of creating custom原创 2013-04-15 22:22:52 · 2243 阅读 · 0 评论 -
Why we should use closures in python
A closure can be a highly efficient way to preserve state across a series of function calls.For example, consider this code that runs a simple counter:def countdown(n): def next():原创 2013-07-22 18:12:58 · 752 阅读 · 0 评论 -
Some tips about Control Flow in Python
1.You can use tuple unpacking to make some for loops cleaner:Bad:somelist = [(1, 2), (3, 7), (9, 5)]result = 0for t in somelist: result = result + (t[0] * t[1])Good:so原创 2013-07-22 18:06:11 · 870 阅读 · 0 评论 -
python 利用绝对路径截取文件夹路径和文件名
使用os.path.dirname() 函数可以轻松处理。例子如下:>>> import os>>> s = 'http://melodi.ee.washington.edu/people/bilmes/mypapers/em.pdf'>>> path = os.path.dirname(s)>>> path'http://melodi.ee.washing原创 2013-04-15 22:51:05 · 13464 阅读 · 0 评论 -
Python总结:字符串处理
(注:最近要给测试同事做一个培训,因此需要总结一些常用的字符处理方法。很多内容总结自 Python cookbook,严格意义上其实不算是原创,但还是融入了一些自己的理解。姑且挂上原创的标签吧。)1. 依次处理字符串中的单个字符(1)可以调用list内置函数,字符串字符串作为参数初始化。theList = list(theString)(2)使用for循环依原创 2013-05-26 23:00:38 · 1540 阅读 · 0 评论 -
【总结】Python 文件操作
1. 几种常用的读取文件的方式:(1) 读取文件file_object = open('thefile.txt')try: for line in file_object: 'process line' passfinally: file_object.close()(2)一次读取所有的原创 2013-06-16 19:51:20 · 1052 阅读 · 0 评论 -
string 模块 maketrans函数 和 translate函数的用法
1.string.maketrans(from, to)Return a translation table suitable for passing to translate(), that will map each character in from into the character at the same position in to; from and to must hav原创 2013-06-16 20:00:03 · 3266 阅读 · 0 评论 -
Python 数值计算的一些常见问题 --- 长期维护
1. 精度round函数, build-in function,round( x[, n]) ,对x保留四舍五入到n位小数2. 整除与浮点除>>> 10/33>>> 10//33>>> float(10)/float(3)3.3333333333333335>>> float(10)//float(3)3.0浮点除法的另一种方法:from原创 2013-01-06 22:07:56 · 1685 阅读 · 0 评论 -
coroutine and yield
Inside a function, the yield statement can also be used as an expression that appears on the right side of an assignment operator.A function that uses yield in this manner is known as a coroutin原创 2013-07-22 18:00:06 · 987 阅读 · 0 评论 -
generator and yield
If a function uses the yield keyword, it defines an object known as a generator. A generator is a function that produces a sequence of values for use in iteration.1.A generator function is a s原创 2013-07-22 17:58:54 · 1058 阅读 · 0 评论 -
Python: fnmatch模块 (Unix B-Shell通配符的文件名匹配)
周末研究Robot Framework的源码分析源码文件 pythonpathsetter.py原创 2014-08-09 15:33:38 · 1776 阅读 · 0 评论
分享