Turn a String into class variable name

  dictionary, python, variables

My problem is the following

I’ve created, in Python, a class let’s imagine it is a character with stats, level etc …

I’ve also created a dictionary in which are listes all the character name and stats, the key of the dictionarry being the name of the character.

I want to create a function that takes in argument the dictionary and that create the characters as an instance of my class. The problem is that i don’t know how to give the character name to my variable, i only have the string corresponding to his name by collecting the key.

Example :

class Character():
       def __init__(self,Name,Age):
                self.Nom=Name
                self.Age=Age


List_Character= {"Roger" : 36, "Kimberley" : 98} 


How can i create a function that takes List_Character and return two instance of Character which variable name are Roger and Kimberley ?

Source: Python Questions

LEAVE A COMMENT