How to use a variable value instead of variable's name in Python

36 Views Asked by At

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

0

There are 0 best solutions below