Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #250

Re: A question about Python Classes

From "Pascal J. Bourguignon" <pjb@informatimago.com>
Newsgroups comp.lang.python, comp.programming
Subject Re: A question about Python Classes
Date 2011-04-21 19:12 +0200
Organization Informatimago
Message-ID <87k4enil5g.fsf@kuiper.lan.informatimago.com> (permalink)
References <2219ee53-e8aa-4ac4-839f-014c3d1b1914@a19g2000prj.googlegroups.com>

Cross-posted to 2 groups.

Show all headers | View raw


chad <cdalten@gmail.com> writes:

> 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?

But you created one!

test is an instance of HomeHandler, which is a subclass of BaseHandler,
so test is also an instance of BaseHandler.

A subclass represents a subset of the instances of its super class.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Back to comp.programming | Previous | NextPrevious in thread | Find similar


Thread

A question about Python Classes chad <cdalten@gmail.com> - 2011-04-21 08:43 -0700
  Re: A question about Python Classes "Pascal J. Bourguignon" <pjb@informatimago.com> - 2011-04-21 19:12 +0200

csiph-web