If I need to have a function do some processing in order to initialize multiple of the object's variable (I'm having a hard time coming up with a simple example that doesn't seem weird).
Which of the following patterns is preferable?
class foo( object ): def __init__(self, bar, bar2): self.bar = bar self.baz, self.square_baz = self.func(bar2) def func(self, bar2): return self.bar + bar2, bar2 * ba2
class foo( object ): def __init__(self, bar, bar2): self.bar = bar self.func(bar2) def func(self, bar2): self.baz = self.bar + bar2 self.square_baz = bar2 * bar2
I feel like in the first pattern, the
__init__ constructor and the processing
func are nicely decoupled. And it's easy to tell what variables each instance of
foo will contain. On the other hand, having to return multiple variables from a function to assign them to an object seems... ugly, yet this seems to be a consequence of the library I'm using.