i have the following class which i use when declaring 'constants' to map one value to another. Is there away in python implement a default method such that anytime an instance of this class referenced without a specific method, a default method is executed?
class FieldMap:
def __init__(self, old_field, new_field):
self._fld_map = (old_field, new_field)
def old_fld(self):
return self._fld_map[0]
def new_fld(self):
return self._fld_map[1]
SEC_ID = FieldMap('value','price')
SEC_NAME = FieldMap('entity_name', 'security_name')
SEC_TICKER = FieldMap('entity_attr', 'ticker')
#Edit: updating example to provide a real example of what i want to achieve
dict = {}
dict['price'] = 1234
print dict[SEC_ID] <--would like this to print out the value 1234 because ideally, the default method would call new_fld() and return 'price'