Please forgive the bad title - I had a hard time trying to think of a concise way to explain this.
I have a Python class that will have some underlying objects of other classes. I want to be able to create these underlying objects via a method of the original object. Let me try to explain better with an example:
class Foo:
def __init__(self):
self.bars = []
def Bar(self, a, b, c):
self.bars.append(Bar(a, b, c))
class Bar:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
I would use the above as such:
f = Foo()
f.Bar(1, 2, 3)
So this works how I want but is kind of crappy with respect to maintenance. Is there a nice "Pythonic" way to do this that would make maintaining this easy? For instance, let's say I changed the constructor of Bar
to:
__init__(self, a, b, c, d):
would there be a way to define all of this so I don't have to update the argument list in 3 places?