Thursday, 12 July 2018

Python __getattr__ Method

Cited from the book "Python How to Program"

When a client program contains the expression time1.attribute as an rvalue (i.e., the right-hand value in an operator expression), Python first looks in time1’s __dict__ attribute for the attribute name.

If the attribute name is in __dict__, Python simply returns the attribute’s value. If the attribute name is not in the object’s __dict__, Python generates the call time1.__getattr__( attribute ) where attribute is the name of the attribute that the client is attempting to access.

No comments:

Post a Comment