I need to get the attribute of different objects to print your content. I thought about using the object argument dynamically, is it possible?
content = getattr("%s" % (variable), "attribute")
I need to get the attribute of different objects to print your content. I thought about using the object argument dynamically, is it possible?
content = getattr("%s" % (variable), "attribute")
Do you mean something like this?
class Custom:
def __init__(self):
self.pet = 'dog'
my = Custom()
variable = 'my'
print(getattr(globals()[variable], 'pet'))
Output:
dog