This is my first question and please understand that I am not a native speaker.
I'm trying to create instances of classes during script parses JSON. Script has dict like:
classes = {'user': 'User', 'chat': 'Chat', 'message': 'Message'}
and classes User
, Chat
, Message
.
When script finds key in json corresponding key in dict I need to create instance of corresponding class.
I found solution, but I think it stupid:
>>> class User():
... name = 'John'
>>> class_name = 'User()'
>>> variable_name = 'user'
>>> exec(f'{variable_name}={class_name}')```