Not sure if this the recommended way of doing things in Python. I have a class with a bunch of attributes, like so
class MyClass:
def __init__(self):
self.attr1 = "first_value"
self.attr2 = "second_value"
...
However, this is tedious, I want to be able to do this in a loop:
self.attr_list = ["attr1", "attr2", "another_attr",...]
def __init__(self, values_list):
self.attr_values = [some_func(i) for i in values_list]
But I also later want to call these values like so:
foo = MyClass(values_list)
...
bar = foo.attr1
myFunc(foo.another_attr, ..., some_other_parameters)
So the question is, how do I avoid the tedious first method where the line for each attribute is hard-coded, but still get the convenience of referring to an attribute without having to know/remember where in the list it is?
Hope this is clearer.
Thanks
P.S. I'm using Python 3