[Tutor] inheriting __init__ arguments

Gonšalo Rodrigues op73418@mail.telepac.pt
Sun Apr 6 15:33:02 2003


This is a multi-part message in MIME format.

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

As in add another argument to B's initializer? e.g.

class B(A):
    def __init__(self, name, address):
        A.__init__(self, name)
        self.address =3D address

Now, with

b =3D B('John Doe', 'Homeless')

you just get his name via b.name.

If you have any questions keep hollering

With my best regards,
G. Rodrigues

  ----- Original Message -----=20
  From: david=20
  To: tutor@python.org=20
  Sent: Saturday, April 05, 2003 10:54 AM
  Subject: [Tutor] inheriting __init__ arguments


  hello everyone.=20
  if i make a class like this

  class A:
      def __init__(self,name):
          self.name=3Dname

  then i make another class that inherits from A its name attribute

  class B(A):
      def __init__(self, address):
          A.__init__(self,name)
          self.address=3Daddress

  but instances of B have addresses also.
  how can B inherit its name from initializing A?

  if my question makes any sense , please explain?


------=_NextPart_000_000E_01C2FB6F.AF86E4B0
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 http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>As in add another argument to B's =
initializer?=20
e.g.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>class B(A):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; def __init__(self, =
name,=20
address):</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
A.__init__(self, name)</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
self.address =3D address</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now, with</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>b =3D B('John Doe', =
'Homeless')</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>you just get his name via =
b.name.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If you have any questions keep=20
hollering</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>With my best regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>G. Rodrigues</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Ddin22@cox.net href=3D"mailto:din22@cox.net">david</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Saturday, April 05, 2003 =
10:54=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] inheriting =
__init__=20
  arguments</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>hello everyone. </FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>if i make a class like =
this</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>class A:</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; def=20
  __init__(self,name):</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  self.name=3Dname</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>then i make another class that =
inherits from A=20
  its name attribute</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>class B(A):</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; def __init__(self, =

  address):</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  A.__init__(self,name)</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  self.address=3Daddress</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>but instances of B have addresses=20
  also.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>how can B inherit its name from =
initializing=20
  A?</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>if my question makes any sense , =
please=20
  explain?</FONT></DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000E_01C2FB6F.AF86E4B0--