"Learning Python" 2nd ed. p479 error?

Mel Wilson mwilson-to at sympatico.ca
Fri May 26 10:17:11 EDT 2006


AbrahamLincolnIllinois at yahoo.com wrote:
> Hello all.
> 
> On page 479, the 2nd edition of the "Learning Python" book, this code
> appears
> 
>     class Derived(Base):
>         def __init__(self, arg, *args, **kw):
>             self.__init__(self, *args, **kw)
> 
> Surely self.__init__ should be
> 
>             Base.__init__
> 
> Everything else in the book has been crystal clear.  Up to page 479!
> It doesn't appear in the errata.  What am I misunderstanding?

Seems to be a typo:

Python 2.4.2 (#1, Jan 23 2006, 21:24:54)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> class A(object):
...   def __init__ (self):
...     print 'Constructing A'
...
 >>> class B(A):
...   def __init__ (self):
...     self.__init__ (self)
...
 >>> B()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "<stdin>", line 3, in __init__
TypeError: __init__() takes exactly 1 argument (2 given)
 >>> class C(A):
...   def __init__ (self):
...     A.__init__ (self)
...
 >>> C()
Constructing A
<__main__.C object at 0x402cf5ac>




         Mel.



More information about the Python-list mailing list