[Tutor] inheriting __init__ arguments

david din22@cox.net
Sat Apr 5 04:54:02 2003


This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C2FB27.0C415620
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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_01C2FB27.0C415620
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 5.50.4923.2500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<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 its=20
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,=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=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 =

explain?</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_000E_01C2FB27.0C415620--