1
def lst_atribute(attribute, record):
    return [x.attribute for x in record]

record is an list which contains objects.

I want to create a list containing the values of an attribute from all the objects.

The objects have many attributes, I want the user to be able to specify the attribute name he wants the values for in the function parameter attribute

But I get the following error

lst_atribute
     return [x.attribute for x in record]
AttributeError: 'Pregnancy' object has no attribute 'attribute'

How can I get the values for an attribute by storing the attributes name in a variable?

kalehmann
  • 4,821
  • 6
  • 26
  • 36

0 Answers0