Expert Python programming - Reading Notes

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Expert Python programming - Reading Notes相关的知识,希望对你有一定的参考价值。

1. MRO: method resolution order

   lookup order:

   L(MyClass) = [MyClass, merged(L(Base1), L(Base2), Base1, Base2)]

 

2. super(...)

   必须所有的父类都call super, 不然会有不可预测的问题

 

3. class variable & instance variable

   查找顺序 

 都可以通过 self.x 访问, 所以instance variable 会覆盖class variable, 而class variable 可以用来定义一个default value for instance variable.

   如果是mutable的,会有些特殊

 

4. descriptor

 只能定义在class level, 可以通过在instance里记录每次设置的value来为每个instance 定义不同的value for class variable

 

以上是关于Expert Python programming - Reading Notes的主要内容,如果未能解决你的问题,请参考以下文章