- 博客(6)
- 收藏
- 关注
翻译 深入浅出 Python Descriptors / Properties
本文由浅入深解释了 Python Descriptors Properties。Descriptor 是定义了__get__(), __set__(), __delete__() 方法的对象。作为类的成员变量时,可以有效的控制 a.x = b 的行为,并引入 @property 概念方便其实现;作为类的成员函数时,可以方便的完成 @classmethod,@staticmethod 的定义
2017-11-06 15:00:45 1642
翻译 深入浅出 Python Decorators
本文由浅入深解释了 Python Decorators。Decorator 本质上是返回函数的函数,是 Closure 的实际应用。利用 Decorator 可以巧妙的返回一个原函数的“增强版”,同时也是很多方法(例如@property,@staticmethod)和库(例如 mock lib @mock.patch('func.xxx'))的实现方法,是 Python 的很精彩的一部分
2017-11-06 00:31:09 2387 2
翻译 深入浅出 Python Closures
本文由浅入深解释了 Python Closures。成为 Closure 的三要素:1. 函数中定义函数2. 内部函数引用了 nonlocal3. 外部函数的返回值是内部函数使用 Closure 的好处有:1. 由数据返回方法2. 函数加工
2017-11-05 22:44:54 611
翻译 深入浅出 Python Generators
本文由浅入深解释了 Python Generators。Generator 即调用之后可以返回 Iterator 的函数Generator 即包含至少一个 yield 的函数,它有两种应用:1. 构造 Iterator2. 使用 Generator 表达式,类似 list comprehension3. 产生 Infinite Stream4. 实现 Continuation
2017-11-05 21:10:15 391
翻译 深入浅出 Python Iterators 迭代器
本文由浅入深解释了 Python Iterators。Iterator 即实现了 __iter__() 和 __next__() 方法的对象Iterator 的一般用在 for x in iterator 中进行循环遍历,是 python 最常用的方法。
2017-11-05 16:47:17 848
原创 virtualenv easy guide
1. InstallationYou must have already installed python two versions, say python27 and python36. Then you should have installed pip. Run either pip or pip3 isntall virtualenv You can type virtualenv -
2017-10-31 20:42:21 145
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人