tags:

views:

36

answers:

1

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
+6  A: 

You can use getattr for this purpose. From the built-in function documentation:

For example, getattr(x, 'foobar') is equivalent to x.foobar.

ezod
Thanks, python is easy!
Vishal