I hav a class which needs to initialize 4 variables returned by a load() function. And in the future the load may return even more variable values. This is my current way of initializing the Runner class. Is there a more normal way or better way to do this?
class Runner(object):
def __init__(self):
self.first, self.second, self.third, self.mapping = self.load()
def load():
...
return (first, second, third, mapping)
self.load()
to set the values of those variables. You COULD usesetattr()
in afor
loop but that's generally not a good idea. You could also try returning adict
fromload()
andself.__dict__ = {**self.__dict__, **self.load()}
but I haven't tried that to confirm.