Reputation: 20627
Like we have in Java Beans util where you pass object and the property name it gives you the value do we have anything similar in python:
def attr(obj, attr)
return obj.attr
Upvotes: 0
Views: 99
Reputation: 7421
You can use getattr
for this purpose. From the built-in function documentation:
For example,
getattr(x, 'foobar')
is equivalent tox.foobar
.
Upvotes: 6