python 內建屬性 getattr 是屬性攔截器,當調用其餘屬性時,會先調用它來看看是否有調用屬性值以前的操做:python
def load_settings(_settings):
class _Settings(object):
def __init__(self, _settings):
self._settings = _settings對象
def __getattr__(self, attr):
return self._settings[attr]
return _Settings(_settings)get