Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am trying to understand when to use __getattr__ or __getattribute__. The documentation mentions __getattribute__ applies to new-style classes. What are new-style classes?

1 Answer

0 votes
by (106k points)

The main difference between __getattr__ and __getattribute__ is that if the attribute was not found by the usual way then __getattr__ is used.

Whereas the __getattribute__ is used before looking at the actual attributes on the object. You will have to use it more consciously otherwise very easily you can end up in infinite recursions.

Related questions

0 votes
1 answer
0 votes
0 answers
asked Feb 17, 2021 by Harsh (1.5k points)
0 votes
1 answer
asked Feb 15, 2021 in SQL by RohitSingh (2.6k points)

Browse Categories

...