I have a lot of variables to initialize with one of my classes, and would rather not type them all out. Is there any way to initialize variables that have the same name as a string?
Semi-Psuedo code:
array1 = ["a", "b", "c", "d", "f"]
array2 = [1, 2, 3, 4, 5]
class test:
def __init__(self, arr1, arr2):
for i, x in enumerate(arr1):
init_var("self." + x) = array2[i]
t = test(array1, array2)
print(t.a)
print(t.b)
This is so that I can access them later in my code, but there are so many specific variables. So far I have been using a dictionary to store all of the values but I would rather have it so that I can retrieve the value straight from the object itself rather than from a dictionary in the object.