Dictionaries have items, and thus use whatever is defined as __getitem__()
to retrieve the value of a key.
Objects have attributes, and thus use __getattr__()
to retrieve the value of an attribute.
You can theoretically override one to point at the other, if you need to - but why do you need to? Why not just write a helper function instead:
Python 2.x:
def get_value(some_thing, some_key):
if type(some_thing) in ('dict','tuple','list'):
return some_thing[some_key]
else:
return getattr(some_thing, some_key)
Python 3.x:
def get_value(some_thing, some_key):
if type(some_thing) in (dict,tuple,list):
return some_thing[some_key]
else:
return getattr(some_thing, some_key)