Behold my simple class:
import sys
class Foo(object):
def __init__(self):
self.frontend_attrs = ['name','ip_address','mode','port','max_conn']
self.backend_attrs = ['name','balance_method','balance_mode']
The init method above creates two lists and I want to refer to them both dynamically:
def sanity_check_data(self):
self.check_section('frontend')
self.check_section('backend')
def check_section(self, section):
# HERE IS THE DYNAMIC REFERENCE
for attr in ("self.%s_attrs" % section):
print attr
But when I do this, python complains about the call to ("self.%s_attrs" % section).
I've read about people using get_attr to find modules dynamically...
getattr(sys.modules[__name__], "%s_attrs" % section)()
Can this be done for dictionaries.
getattr(self, '{}_attrs'.format(section))