I am working on a project, and I will be creating an instance from a dictionary. The dictionary will contain instance attributes, and one special attribute called __class__
, which will hold the name of the instance's class:
Example:
{'name': "John", 'age': "15", '__class__': "person"}
So I will need to create a new instance that will have the attributes name, age, and of class "Person". Equivalently --> new_instance = Person()
But I want to do it dynamically from my program.
How can I do this? I have read that you can do this with eval
, but how?