another question about classes and subclassing
Gregory Ewing
greg.ewing at canterbury.ac.nz
Wed May 19 04:22:21 EDT 2010
Dave Angel wrote:
> Inside the __init__() method of Submarine, simply call the __init__()
> method of Craft, with appropriate parameters.
To elaborate on that a little, it looks like this:
class Craft:
def __init__(self, position):
self.position = position
class Submarine(Craft):
def __init__(self, position, depth):
Craft.__init__(self, position)
self.depth = depth
Note the explicit 'self' passed to the __init__ method
of Craft. This is necessary because you are calling the
method's underlying function directly, bypassing the
magic which normally inserts 'self' automatically.
--
Greg
More information about the Python-list
mailing list