[Tutor] Inheritance Question

Joel Ricker joejava@dragoncat.net
Sun, 24 Feb 2002 22:02:35 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C1BD7E.F7F76880
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ok, I've now played with rfc822 and the mime related modules to get an =
idea of how things work and what direction I want to go.  To get a feel =
for inheritance, I decided to make up a class called POP3Search which =
would inherit from poplib.POP3 (which connects to a pop3 server and =
queries for messages) with the extra features of message caching and =
search.

This is what I have:

import poplib

class POP3Search(poplib.POP3):
    """Create a connection to a POP3 mailserver and search for =
messages"""
   =20
    def __init__(self, host =3D "", port =3D 110):  =20
        poplib.POP3(host, port)      =20
   =20
if __name__ =3D=3D "__main__":
    s =3D POP3Search("pop3.mailserver")
    print s.getwelcome()

Now my understanding is -- and I guess I'm wrong -- is that POP3Search =
will inherit the attributes of POP3 so that getwelcome() when run will: =
Look in the child -- since none found, look in the parent -- executes =
that and returns the result.  getwelcome returns self.welcome -- self in =
this case being the parent.  Since welcome isn't found in the current =
class (POP3Search), find it in the parent (POP3).  Any case I'm getting =
an error that its not being found:

 File "C:\PYTHON22\lib\poplib.py", line 172, in getwelcome
    return self.welcome
AttributeError: POP3Search instance has no attribute 'welcome'

What can I do to fix (and understand this)? =20
Thanks

Joel


------=_NextPart_000_0013_01C1BD7E.F7F76880
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3314.2100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Ok, I've now played with rfc822 and the =
mime=20
related modules to get an idea of how things work and what direction I =
want to=20
go.&nbsp; To get a feel for inheritance, I decided to make up a class =
called=20
POP3Search which would inherit from poplib.POP3 (which connects to a =
pop3 server=20
and queries for messages) with the extra features of message caching and =

search.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This is what I have:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>import poplib</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>class=20
POP3Search(poplib.POP3):<BR>&nbsp;&nbsp;&nbsp; """Create a connection to =
a POP3=20
mailserver and search for messages"""<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; def __init__(self, host =3D "", port =3D =
110):&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poplib.POP3(host,=20
port)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>if =
__name__=20
=3D=3D "__main__":<BR>&nbsp;&nbsp;&nbsp; s =3D=20
POP3Search("pop3.mailserver")<BR>&nbsp;&nbsp;&nbsp; print=20
s.getwelcome()</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now my understanding is -- and I guess =
I'm wrong --=20
is that POP3Search will inherit the attributes of POP3 so that =
getwelcome() when=20
run will: </FONT><FONT face=3DArial size=3D2>Look in the child -- since =
none found,=20
look in the parent -- executes that and returns the result.&nbsp; =
getwelcome=20
returns self.welcome -- self in this case being the parent.&nbsp; Since =
welcome=20
isn't found in the current class (POP3Search), find it in the parent=20
(POP3).&nbsp;&nbsp;Any case I'm getting an error that its not being=20
found:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;File "C:\PYTHON22\lib\poplib.py", =
line 172,=20
in getwelcome<BR>&nbsp;&nbsp;&nbsp; return =
self.welcome<BR>AttributeError:=20
POP3Search instance has no attribute 'welcome'</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What can I do to fix (and understand =
this)?&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Joel</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0013_01C1BD7E.F7F76880--