Classes, Inheritance - Stupid lazy question

Paul Gresham gresham at mediavisual.com
Wed Apr 12 12:14:40 CEST 2000


"Janko Hauser" <jhauser at ifm.uni-kiel.de> wrote in message
news:87zoqz4p9n.fsf at ifm.uni-kiel.de...
> Michael Hudson <mwh21 at cam.ac.uk> writes:
>
> > Nononono; think about what happens if you do this:
> >
> > class bob(paul):
> >    pass
> >
> > bob("adam").fired()
> >
> > What *I* think you want is:
> >
> > class paul(lazy):
> >     def __init__(self, name):
> >         lazy.__init__(self,name)
> >         self.april_pay = 0
> >
> >     def fired(self):
> >         print "Here's a box, collect the things from your desk"
> >         lazy.fired(self)
> >
> > After all, if you're going to inherit from a class, you must have
> > access to it, right?
> >
>
> I see, this is clearly better. But I do not understand, where the
> class/instance?? of lazy.__init__() is stored.

In this way the lazy class does not have an instance, but we can still call
its member functions, as if they were a normal function. By passing them our
instance of self, then our self will also be initialised. In the above
example we can do this without risk, as we are inheriting from lazy, so we
have all attributes.

>
> Some more slaps on the head, please :-)
>
> __Janko
>
> --
>   Institut fuer Meereskunde             phone: 49-431-597 3989
>   Dept. Theoretical Oceanography        fax  : 49-431-565876
>   Duesternbrooker Weg 20                email: jhauser at ifm.uni-kiel.de
>   24105 Kiel, Germany





More information about the Python-list mailing list