Built-in functions Table of Contents getattr, setattr, Why need them? getattr, setattr, Why need them? discussion somevar = 'foo' getattr(x, somevar) getattr(x, somevar, 0) # also can specify default value https://stackoverflow.com/questions/19123707/why-use-setattr-and-getattr-built-ins