I came across the __getattr__ built-in and was wondering when it would be used. I had a hard time thinking of a practical use from the documentation
http://docs.python.org/reference/datamodel.html#. What would be an actual example of how it could be used and useful in code?
I came across the __getattr__ built-in and was wondering when it would be used.
Share
One example is to use object notation with dictionaries. For example, consider a dictionary
Typically in Python one accesses the ‘value’ variable as
which will print
1at the Python interpreter. However, one may wish to use themyDict.valuenotation. This may be achieved by using the following class: