👋 Hey there, I am Waylon Walker
I am a Husband, Father of two beautiful children, Senior Python Developer currently working in the Data Engineering platform space. I am a continuous learner, and sha
This week I learned the power of getattr in python. I am using an API that returns an object that is not subscriptable. Attributes are accessed with .thing for instance. Its really nice that it tab completes, but it makes it really hard to loop through and access 10 items. I learned that you can get to them dynamically with getattr.
This week I learned the power of getattr in python. I am using an API that returns an object that is not subscriptable. Attributes are accessed with
.thing
for instance. Its really nice that it tab completes, but it makes it really hard to loop through and access 10 items. I learned that you can get to them dynamically with getattr.The backend library essentially looks like this.
It gets instansiated with a dictionary.
You can ask for individual items by dot notation, and tab completion works.
but it's not subscriptable
So how do you dynamically access it by a string? The answer is getattr!
Python is such a wonderful and hackable language