![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
路虽远在路上
视财如命
展开
-
Python 多层装饰器
前言Python 的装饰器能够在不破坏函数原本结构的基础上,对函数的功能进行补充。当我们需要对一个函数补充不同的功能,可能需要用到多层的装饰器。在我的使用过程中,遇到了两种装饰器层叠的情况,这里把这两种情况写下来,作为踩坑记录。情况1def A(funC): def decorated_C(funE): def decorated_E_by_CA(*args, **kwarg原创 2017-05-05 10:26:48 · 4472 阅读 · 0 评论 -
python 的返回值为list 的 property 绕过 setter 的问题
当用property装饰一个属性,并且这个属性返回的是一个list(或者一个类,一个dict,都会有同样的情况),那么如果我们使用list的索引去访问list,setter将不起任何作用。 如下所示:In [1]: class test(object): ...: a = [10,10,10] ...: @property ...: def ads(原创 2017-05-05 15:18:47 · 743 阅读 · 0 评论