I am looking for the possibility to add a variable amount of attributes to a class in python using a list.
class X():
def __init__(self,mylist):
for element in list:
self.element = ''
So if I have
tabs = ['food','name','map']
I will get a class with attributes as follows (pseudocode)
myclass = X(['food','name','map'])
print(X.food)
''
I will be able later on to modify X.food from other class.
LATE EDIT: The question: How to access object attribute given string corresponding to name of that attribute is similar but does not use a list to provide names or arguments to the class. Moreover in that particular question setattr is not used in any of the answers. Hence the answers of this question are the ones to follow.