Python
文章平均质量分 67
yangxkl
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
目前见到的最Make Sense的Python Guide
Github上Python板块排名第一的大神写的: http://docs.python-guide.org/en/latest/原创 2015-03-26 20:22:28 · 530 阅读 · 0 评论 -
Implement queue with Python list
# Completed implementation of a queue ADTclass Queue: def __init__(self): self.data = [] def is_empty(self): return self.data == [] def enqueue(self, item): self原创 2015-03-24 11:13:33 · 1112 阅读 · 0 评论 -
Implement Deque with Python list
# Completed implementation of a deque ADTclass Deque: def __init__(self): self.data = [] def is_empty(self): return self.data == [] def add_front(self, item): se原创 2015-03-24 11:15:49 · 526 阅读 · 0 评论 -
comparison of four ways to generating a list
from time import timedef timeit(func): '''Use this decorator to measure execution time of a function. eg. @timeit def yourFunction(args): dosomething... '''原创 2015-03-23 14:47:43 · 473 阅读 · 0 评论 -
Python 装饰器
Python有一个有趣的特征叫做装饰器,可以向已存在的代码添加功能。这也被称作元编程(metaprogramming, 编写操纵其它程序的程序,企图在运行时完成部分本应在编译时完成的工作)Ref:metaprogramming热身为了理解装饰器,我们首先应该知道以下几点:一切皆对象我们所定义的名称仅仅是对象的标识函数也是对象不同的名称可以绑定到相同的对象来看一个例子:翻译 2015-03-21 17:01:18 · 437 阅读 · 0 评论 -
Python 闭包
原文:http://www.programiz.com/python-programming/closure一个函数定义在另一个函数内部叫做嵌套函数。嵌套函数。嵌套的函数能够访问enclosing scope作用域的变量。在Python中,非局部(non-local)变量是只读的,如果要修改它们必须使用nonlocal关键字显示申明。下面是一个嵌套函数访问非局部变量的例子:de翻译 2015-03-21 15:51:51 · 1491 阅读 · 0 评论 -
为什么我在scrapy shell中没有看到hxs和xxs
如题,其中一个可能的原因是使用的scrapy版本问题:在0.16下:参考:http://doc.scrapy.org/en/0.16/intro/tutorial.htmlscrapy shell http://www.dmoz.org/Computers/Programming/Languages/Python/Books/[ ... Scrapy log here ... ]原创 2015-03-30 14:42:08 · 2189 阅读 · 0 评论 -
Using __iadd__ & __radd__
# Right-Side and In-Place Uses: __radd__ and __iadd__# Why we need Right-Side Addition>>> class Adder:... def __init__(self, value=0):... self.data = value... def __add__(self原创 2015-03-21 09:29:37 · 867 阅读 · 0 评论 -
Python 编码风格
原文:https://code.google.com/p/zhong-wiki/wiki/PEP8Python 编码风格指南 Horin|贺勤 Email: horin153@msn.com Blog: http://blog.youkuaiyun.com/horin153/ PEP: 8 Title: Style Guide for Python Code Version: 54转载 2015-03-17 11:36:44 · 738 阅读 · 0 评论 -
When to use __new__ vs __init__
Use __new__ when you need to control the creation of a new instance.Use __init__ when you need to control initialization of a new instance.__new__ is the first step of instance creation. It's call转载 2015-03-20 18:03:24 · 425 阅读 · 0 评论 -
Python 中的常见陷阱
大多数情况下,Python旨在写出干净,一致的代码,避免奇怪的做法。但是,对新手来说有时却不是这样。可变的(Mutable)默认参数可能你写的代码像这样:def append_to(element, to=[]): to.append(element) return to你期望的运行结果:my_list = append_to(12)print my_list翻译 2015-03-27 10:50:49 · 2212 阅读 · 0 评论 -
What does PEP stand for in Python
PEP stands for Python Enhancement Proposal. A PEP is a design document providing information to the Python community, or describing a new feature for Python or its processes or environment. The PEP原创 2015-03-20 09:29:14 · 815 阅读 · 0 评论 -
Files Operation in Python
# 基本的文件读写操作#-------------------------------------------------------------------------------------output = open(r'D:\text', 'w') # 创建输出文件用于写操作input = open('D:\text', 'r') # 创建输入文件用于读操作原创 2015-03-16 14:04:46 · 490 阅读 · 0 评论 -
Implement stack with Pyhon list
class Stack: '''Implement a stack using list''' def __init__(self, L=[]): self.data = L def push(self, item): self.data.append(item) def pop(self): return sel原创 2015-03-23 18:29:44 · 365 阅读 · 0 评论
分享