Python: using getattr for properties and methods

Adrienne Domingus
2 min readAug 24, 2019
Photo by Émile Perron on Unsplash

Using getattr

Before we jump into how getattr can be a useful tool for DRYing up our code, lets cover how it works (docs here)! In short, it takes an object and a string version of a property name, and returns the value of that property, if it exists on an object. It can optionally take a default value to return if the attribute can’t be found on the object, and otherwise…