i want to create an object of My_Class
and want to tell it with a string what dictionary to get. Is there a better way than to do it with if
?
object_dictionary = {
"car" : "some_car",
"house" : "some_house",
"animal" : "some_animal"
}
class My_Class:
def __init__(self, string):
if string == "object_dictionary":
self.dictionary = object_dictionary
obj = My_Class("object_dictionary")
If I want to choose between more dictionaries this will be inconvenient. How can I do this?
object_dictionary = {
"car" : "some_car",
"house" : "some_house",
"animal" : "some_animal"
}
class My_Class:
def __init__(self, string):
self.dictionary = string
obj = My_Class("object_dictionary")