[Tutor] Little subclass understanding problem
Tom
tavspamnofwd at googlemail.com
Thu Nov 15 19:35:49 CET 2007
I am trying to understand what happens in the following scenario:
class Sub_class(Base_class):
def __init__(self, data):
Base_class.__init__(self, data)
as in:
# snippet from http://viner.tv/go?set
class Set(list):
def __init__(self, value = []):
list.__init__([])
The last line is the one I don't understand. Nothing appears to be
assigned or instantiated.
I have just re-read the relevant part of Wesley Chun's 'Core' book,
again, and think I *may* understand.
Base_class.__init__(self, data)
is *kind of* like saying:
self.Base_class.__init__(data)
i.e. it's doing something *to* self. But then the 2nd example above
doesn't make sense! It looks like list.__init__([]) is doing something
special just because of where it is, i.e. in the class definition of a
subclass of list.
Help!
If anyone has a better way of explaining this / thinking about this, I
would be most grateful!
More information about the Tutor
mailing list