<div>Remember the mantra, "Explitic is better than implicit." ;-)<br clear="all"></div><div><br></div>~/santa<br>
<br><br><div class="gmail_quote">On Tue, Mar 8, 2011 at 7:15 PM, Martin De Kauwe <span dir="ltr"><<a href="mailto:mdekauwe@gmail.com">mdekauwe@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Mar 9, 12:53 pm, "Rhodri James" <<a href="mailto:rho...@wildebst.demon.co.uk">rho...@wildebst.demon.co.uk</a>><br>
wrote:<br>
> On Wed, 09 Mar 2011 01:00:29 -0000, Martin De Kauwe <<a href="mailto:mdeka...@gmail.com">mdeka...@gmail.com</a>> <br>
<div><div class="h5">> wrote:<br>
><br>
> > class BaseClass(object):<br>
> > def __init__(self, a, b, c, d):<br>
> > self.a = a<br>
> > self.b = b<br>
> > self.c = c<br>
> > self.d = d<br>
><br>
> > class NewClass(BaseClass):<br>
> > def __init__(self):<br>
> > super(NewClass, self).__init__(new)<br>
> > self.new = new<br>
> > print self.new<br>
><br>
> Two things leap out immediately. First, BaseClass.__init__ takes four <br>
> parameters besides `self`, but when you call it you only give it one <br>
> parameter, `new`. It's not going to like that. Second, where did `new` <br>
> come from? It's not a parameter to NewClass.__init__, and it doesn't seem <br>
> to be a global. That's not going to work well either.<br>
><br>
> However neither of these things are what the traceback is complaining <br>
> about.<br>
><br>
> > if __name__ == "__main__":<br>
><br>
> > A = PreviousClass(1, 2, 3, 4, 5)<br>
> > B = NewClass(1, 2, 3, 4, 5)<br>
><br>
> > $ python test.py<br>
> > Traceback (most recent call last):<br>
> > File "model_data.py", line 29, in <module><br>
> > B = NewClass(1, 2, 3, 4, 5)<br>
> > TypeError: __init__() takes exactly 1 argument (6 given)<br>
><br>
> When you create your NewClass, you give it five parameters (1, 2, 3, 4, 5) <br>
> plus the implicit `self`, which is the "(6 given)" part of the message. <br>
> However NewClass.__init__ takes no parameters aside from `self` (i.e. it <br>
> "takes exactly 1 argument"). There's a mismatch between what you've told <br>
> NewClass.__init__ to expect and what you actually deliver to it.<br>
><br>
> The point that may be confusing you is that NewClass.__init__ knows <br>
> nothing at all about BaseClass.__init__. It doesn't inherit parameters <br>
> from it or anything magical like that; you have to tell it everything. If <br>
> you want parameters to pass from NewClass.__init__ to BaseClass.__init__ <br>
> you will have to provide them somehow. In this case, I think what you <br>
> meant was something like this:<br>
><br>
> class NewClass(BaseClass):<br>
> def __init__(self, a, b, c, d, new):<br>
> super(NewClass, self).__init__(a, b, c, d)<br>
> self.new = new<br>
> # etc<br>
><br>
> --<br>
> Rhodri James *-* Wildebeest Herder to the Masses<br>
<br>
</div></div>Yep that was it, I think I misunderstood and assumed it knew about<br>
stuff in the BaseClass constructor. All makes sense now!<br>
<div><div class="h5">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>