[Tutor] Question about Classes
Alan Gauld
alan.gauld at blueyonder.co.uk
Tue Nov 25 18:00:36 EST 2003
> > Since the Email class seems to collect emails (plural), it
seems
> > it would be better to call is "Emails". If you use it through
> > an "emails" attribute in the Contact, ...
> > class Emails:
> > def __init__(self):
> > self._emails=[]
_emails is an attribute of the Email class.
> > def show(self):
> > def add(self, email, type):
> >
> >> class Contact(Email):
> >> def __init__(self...
> >> self.firstName=firstName
> >> self.lastName=lastName
> > self.emails = Emails()
emails is an attribute of the Contact class
> > p.emails.add('x', 'yyy')
Which adds an entry to the Emails class in the p contact
> You lost me here. In the preceding section you
> define _email and yet you refer to email in this
> last bit. Does the underscore perform some sort of magic?
Not really its just a convention to indicate in internal
member of a class. The real point is that Magnis has
declared two different variables, one in the Emails
class(_emails) and one in the Contact class(emails).
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
PS. Welcome back to the tutor list Magnus
More information about the Tutor
mailing list