469,352 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Is this not infinite?

From a book:

class Derived(Base):
def __init__(self, etc....):
self.__init__(self, etc...)

I don't understand why the 'self' in the call to the Base class
constructor doesn't still refer to the Derived instance. If you say:

x = Derived()

then that triggers the def above. And then that function calls a
constructor, but if it's calling x.__init__, and x is a Derived
instance, it seems like the function keeps calling itself.

Obviously I'm missing a piece of information that would help me to see
why the call gets passed back up to Base...
Mar 7 '06 #1
3 884
John Salerno wrote:
From a book:

class Derived(Base):
def __init__(self, etc....):
self.__init__(self, etc...)
This should be
def __init__(self, etc....):
Base.__init__(self, etc...)

or possibly
def __init__(self, etc....):
super(Derived, self).__init__(etc...)
Obviously I'm missing a piece of information that would help me to see
why the call gets passed back up to Base...


It's a typo in the book.

Kent
Mar 7 '06 #2
Kent Johnson wrote:
This should be
def __init__(self, etc....):
Base.__init__(self, etc...) It's a typo in the book.


Thank goodness! At least I know my mind is heading in the right
direction then... :)
Mar 7 '06 #3
John Salerno wrote:
Kent Johnson wrote:

This should be
def __init__(self, etc....):
Base.__init__(self, etc...)


It's a typo in the book.


Thank goodness! At least I know my mind is heading in the right
direction then... :)


Which book? Many of the authors are here, and I don't recall seeing
that one reported before. These things can sometimes be "patched" in an
errata page for the book, or at least noted here for posterity in case
anyone else tries searching.

-Peter

Mar 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by Gremlin | last post: by
5 posts views Thread by mailpitches | last post: by
4 posts views Thread by LOPEZ GARCIA DE LOMANA, ADRIAN | last post: by
44 posts views Thread by James Watt | last post: by
10 posts views Thread by bhipwell via AccessMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.