another question about classes and subclassing
Gregory Ewing
greg.ewing at canterbury.ac.nz
Wed May 19 04:15:30 EDT 2010
Alex Hall wrote:
> So by calling submarine(craft) I am bringing
> in all of craft's attribs (subclassing)? Or does calling craft's
> __init__ method do that instead?
By making Submarine a subclass of Craft, you are inheriting
any methods, or other class attributes, defined in the
classes themselves.
Instance attributes are a little different -- they only
come into existence when you assign to them, which is
usually done for the first time in the __init__ method.
Each instance has its own dictionary that holds the
values of its instance attributes, and it's just a
flat namespace -- there is no real distinction between
an instance attribute of a class or a subclass.
Any "inheritance" of instance attributes is just a
consequence of one __init__ method calling another.
--
Greg
More information about the Python-list
mailing list