[Tutor] Inheritance Question

Karthik Gurumurthy karthikg@aztec.soft.net
Mon, 25 Feb 2002 09:03:10 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_0036_01C1BDDB.3FBFB3A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

[karthik Guru] >> you need to call the base class constructor to
initialise the attribute "welcome". I guess welcome is getting defined
in poplib.POP3's constructor.
methods are inherited w/o any explicit call to the base constructor but
attributes are not unless explicitly done.
 
    def __init__(self, host = "", port = 110):   
        poplib.POP3.__init__(host, port)       

 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).  
[karthik Guru] >> 
No i think self will always be the of type derived class if the method
gets invoked through a derived class reference. you can try printing the
type of self int he base class.
 
karthik.


------=_NextPart_000_0036_01C1BDDB.3FBFB3A0
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"MSHTML 5.50.4616.200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D084462403-25022002><SPAN =

class=3D084462403-25022002><FONT color=3D#0000ff>[karthik=20
Guru]&nbsp;&gt;&gt;</FONT></SPAN>&nbsp;you need to call the base class=20
constructor to initialise the attribute "welcome". I guess welcome is =
getting=20
defined in poplib.POP3's constructor.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D084462403-25022002>methods are=20
inherited w/o any explicit call to the base constructor but attributes =
are not=20
unless explicitly done.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D084462403-25022002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; def __init__(self, =
host =3D "",=20
port =3D 110):&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
poplib.POP3<SPAN class=3D084462403-25022002>.__init__</SPAN>(host,=20
port)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D084462403-25022002><FONT=20
  color=3D#0000ff>&nbsp;</FONT></SPAN>getwelcome returns self.welcome =
-- self in=20
  this case being the parent.&nbsp; Since welcome isn't found in the =
current=20
  class (POP3Search), find it in the parent =
(POP3).&nbsp;&nbsp;<BR><SPAN=20
  class=3D084462403-25022002><FONT color=3D#0000ff><SPAN=20
  class=3D084462403-25022002><FONT color=3D#0000ff>[karthik=20
  =
Guru]&nbsp;&gt;&gt;</FONT></SPAN>&nbsp;</FONT></SPAN></FONT></FONT></DIV=
>
  <DIV><FONT face=3DArial><FONT color=3D#0000ff size=3D2><SPAN=20
  class=3D084462403-25022002>No i think self will always be the of type =
derived=20
  class if the method gets invoked through a derived class reference. =
you can=20
  try printing the type of self int he base =
class.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT color=3D#0000ff size=3D2><SPAN=20
  class=3D084462403-25022002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT color=3D#0000ff size=3D2><SPAN=20
  =
class=3D084462403-25022002>karthik.</SPAN></FONT></FONT></DIV></DIV></BL=
OCKQUOTE></BODY></HTML>

------=_NextPart_000_0036_01C1BDDB.3FBFB3A0--