A question about Python Classes

Benjamin Kaplan benjamin.kaplan at case.edu
Thu Apr 21 13:10:24 EDT 2011


On Apr 21, 2011 12:55 PM, "chad" <cdalten at gmail.com> wrote:
>
> On Apr 21, 9:30 am, Jean-Michel Pichavant <jeanmic... at sequans.com>
> wrote:
> > chad wrote:
> > > Let's say I have the following....
> >
> > > class BaseHandler:
> > >     def foo(self):
> > >         print "Hello"
> >
> > > class HomeHandler(BaseHandler):
> > >     pass
> >
> > > Then I do the following...
> >
> > > test = HomeHandler()
> > > test.foo()
> >
> > > How can HomeHandler call foo() when I never created an instance of
> > > BaseHandler?
> >
> > > Chad
> >
> > you did, test is an instance of BaseHandler.
> >
> >  > isinstance(test, HomeHandler)
> > < True
> >
> >  > isinstance(test, BaseHandler)
> > < True
> >
>
> So it just just creates an instance of every class that it inherits?
>
> Chad

No. it is an instance of every class it inherits. It's called inheritance
because it inherits the attributes and methods of the parent class
> --
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110421/72fcd638/attachment.html>


More information about the Python-list mailing list