这里补充一下 __getattribute__ ,参考: A key difference between __getattr__ and __getattribute__ is that __getattr__ is only invoked if the attribute wasn't found the usual ways. It's good for implementing a fallback for missing attributes, and is probably the one of two you want. 翻译: __getattr__ 和 __getattribute__ 之间的一个关键区别是,只有当属性无法通过通例方式找到时,才会调用 __getattr__ 。它非常恰当实现缺失属性的后备,并且可能是您想要的两个方法之一。元类的实际应用场景
Simple is better than complex.除非确实需要元类的强盛功能,否则利用更简单的解决方案可能是更好的选择。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |