![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
Charles_lgc
Stay hungry, Stay foolish
展开
-
深入浅出 Python Descriptors / Properties
本文由浅入深解释了 Python Descriptors Properties。Descriptor 是定义了__get__(), __set__(), __delete__() 方法的对象。作为类的成员变量时,可以有效的控制 a.x = b 的行为,并引入 @property 概念方便其实现;作为类的成员函数时,可以方便的完成 @classmethod,@staticmethod 的定义翻译 2017-11-06 15:00:45 · 1626 阅读 · 0 评论 -
深入浅出 Python Closures
本文由浅入深解释了 Python Closures。成为 Closure 的三要素:1. 函数中定义函数2. 内部函数引用了 nonlocal3. 外部函数的返回值是内部函数使用 Closure 的好处有:1. 由数据返回方法2. 函数加工翻译 2017-11-05 22:44:54 · 603 阅读 · 0 评论 -
深入浅出 Python Decorators
本文由浅入深解释了 Python Decorators。Decorator 本质上是返回函数的函数,是 Closure 的实际应用。利用 Decorator 可以巧妙的返回一个原函数的“增强版”,同时也是很多方法(例如@property,@staticmethod)和库(例如 mock lib @mock.patch('func.xxx'))的实现方法,是 Python 的很精彩的一部分翻译 2017-11-06 00:31:09 · 2368 阅读 · 2 评论 -
深入浅出 Python Iterators 迭代器
本文由浅入深解释了 Python Iterators。Iterator 即实现了 __iter__() 和 __next__() 方法的对象Iterator 的一般用在 for x in iterator 中进行循环遍历,是 python 最常用的方法。翻译 2017-11-05 16:47:17 · 833 阅读 · 0 评论 -
深入浅出 Python Generators
本文由浅入深解释了 Python Generators。Generator 即调用之后可以返回 Iterator 的函数Generator 即包含至少一个 yield 的函数,它有两种应用:1. 构造 Iterator2. 使用 Generator 表达式,类似 list comprehension3. 产生 Infinite Stream4. 实现 Continuation翻译 2017-11-05 21:10:15 · 382 阅读 · 0 评论