total idiot question: +=, .=, etc...
Guido van Rossum
guido at cnri.reston.va.us
Tue Jun 29 07:27:05 EDT 1999
Greg Ewing <greg.ewing at compaq.com> writes:
> > class A(B):
> > def __init__(self, x, y, z):
> > B.__init__(self, x, y, z)
>
> I could live with having to explicitly name the
> superclass, provided something checked that the
> class I named was actually a direct base class
> of the one where the method is defined. That
> way things would be less likely to break
> mysteriously when I rearrange the class
> hierarchy.
Oh, but that check *is* being made! (In fact this is the same check
that prevents "class methods" from working ;-)
>>> class A:
def __init__(self):
self.a = 1
>>> class B:
def __init__(self):
self.b = 1
>>> class C(B):
def __init__(self):
A.__init__(self)
>>> C()
Traceback (innermost last):
File "<pyshell#12>", line 1, in ?
C()
File "<pyshell#11>", line 3, in __init__
A.__init__(self)
TypeError: unbound method must be called with class instance 1st argument
>>>
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list