[Tutor] Question about Classes
Alan Gauld
alan.gauld at blueyonder.co.uk
Tue Nov 25 17:05:34 EST 2003
> By subclassing the class "Email", you are overwriting the
__init__ function
> in the Email class. This means that the instance of Contact has
no clue about
> the statement:
>
> self.emails = []
>
> in the Email class. You can try placing this statement in the
__init__ of
> Contact, or make it all one class, or whatever else you might
think of.
Or call the Email init function within the Contact init:
Email.__init__(self)
This is normally good practice when creating subclasses anyhow.
Initialise the parent then do the local initialisation.
> > class Email:
> > def __init__(self):
> > self.emails=[]
> >
> >
> > class Contact(Email):
> > def __init__(self
> > ,firstName=''
> > ,lastName=''
> > ):
> > """ Initial object """
Email.__init__(self)
> > self.firstName=firstName
> > self.lastName=lastName
> >
Alan G.
More information about the Tutor
mailing list