|
|
|
|
|
by csdigi
4723 days ago
|
|
The sectioned titled "Inconsistent get interface" compares get() to getattr() which are two unrelated functions. getattr is the same as a property lookup on an object (person.name, person['name']), get() is a method defined by some types which returns a stored value. In the provided example he calls get on an empty dictionary for the key 1, then calls getattr of 'a' on an int. Finally he calls it again with an optional default argument of None. The difference is made apparent by the example: In [13]: test = {'values': 1} In [14]: getattr(test, 'values')
Out[14]: <function values> In [15]: test.get('values')
Out[15]: 1 |
|