Difference between __getattr__ vs __getattribute__

前端 未结 8 1318
甜味超标
甜味超标 2020-11-22 12:54

I am trying to understand when to use __getattr__ or __getattribute__. The documentation mentions __getattribute__ applies to new-sty

8条回答
  •  生来不讨喜
    2020-11-22 13:15

    New-style classes are ones that subclass "object" (directly or indirectly). They have a __new__ class method in addition to __init__ and have somewhat more rational low-level behavior.

    Usually, you'll want to override __getattr__ (if you're overriding either), otherwise you'll have a hard time supporting "self.foo" syntax within your methods.

    Extra info: http://www.devx.com/opensource/Article/31482/0/page/4

提交回复
热议问题