What's the purpose the hook method showing in a class definition?

Richard Damon Richard at Damon-Family.org
Sun Oct 20 07:26:16 EDT 2019


On 10/20/19 4:34 AM, jfong at ms4.hinet.net wrote:
> Yes, there will be an attribute error if no goo() was defined. 
>
> What puzzles me is how a parent's method foo() can find its child's method goo(), no matter it was overwrote or not? MRO won't explain this and I can't find document about it also:-(
>
> --Jach

The simple answer is that the attribute lookup happens at run time, not
compile time (unlike some other languages). Thus attributes/member
functions can be added by sub-classes, or even just to that instance at
run time and be found.

-- 
Richard Damon




More information about the Python-list mailing list