0

Sorry if the title sounds weird im new here

here's my problem

def populate(self, att, obj):
        ans = []
        for item in att:
            item = item.replace(obj.__class__.__name__, "")
            ans.append(item)
        for mem in ans:
            self.table.add_row(f"{obj.}")
        self.console.print(self.table)

my pain point is in bolds so my obj. has 3 data members, their names are stored in the ans list, now i want the table.add function to add 3 entries but i need to call them my obj.name_of_data_member, the mem variable has the data member but i can't just do obj.mem So a little help would be appreciated. thanks

So i am expecting to call over each data member from their names stored in the list ans like obj.name, obj.price etc

Siddharth
  • 1
  • 1
  • 1
    Your code is incomplete. But I think the answer is to use `getattr(obj, mem)`. – Robin De Schepper Jan 19 '23 at 15:53
  • 1
    Hey, welcome to stackoverflow! Please read the information on [how to ask a question](https://stackoverflow.com/help/how-to-ask) and what a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) is. – Frederic Jan 19 '23 at 15:54

0 Answers0