trouble understanding inheritance...

Simon Forman rogue_pedro at yahoo.com
Wed Aug 16 15:24:42 EDT 2006


KraftDiner wrote:
> Fredrik Lundh wrote:
> > KraftDiner wrote:
> >
> > > This is not working the way I think it should....
> > > it would appear that fromfile and getName are calling the baseClass
> > > methods which are
> > > simple passes.... What have I done wrong?
> > >
> > > class baseClass:
> > > 	def __init__(self, type):
> > > 		if type == 'A':
> > > 			self = typeA()
> > > 		else:
> > > 			self = typeB()
> >
> > __init__ is not a constructor, and assigning to self doesn't change the
> > type of the constructed object.
> >
> > looks like you need to get a better tutorial.
> >
> > </F>
>
> Well how does one select which class baseClass really is when you
> contruct the object?
> What am I missing?
>
> a = typeA()
> b = typeB()
> c = baseClass(a)

a = typeA()
b = typeB()

You're done. Stop there.

You can't "select which class baseClass really is"-- it really is
baseClass.  You "select" which class your object is by choosing which
class to use to construct the object.

HTH,
~Simon




More information about the Python-list mailing list