Suppose I have a model object.
print (dir(table)) [\'...\', \'col1\', \'col2\', \'...\'] # this will output column 1 value print (table.col1)
To get attribute value by name use getattr
getattr
getattr(table, 'col1')
You want to use getattr when doing dynamic attribute retrieval in python:
col = 'col1' getattr(table, col)