Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.04; 'instance': 0.05; 'pascal': 0.07; 'from:addr:python': 0.09; 'subclass': 0.09; 'this:': 0.11; '>>>': 0.12; 'def': 0.13; 'wrote:': 0.14; 'chad': 0.16; "didn't,": 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'subject:Classes': 0.16; 'writes:': 0.20; 'header:In-Reply-To:1': 0.22; 'subject:question': 0.22; 'received:84': 0.25; 'skip:b 20': 0.27; 'pass': 0.27; 'class': 0.29; 'to:addr:python-list': 0.32; 'created': 0.33; 'test': 0.33; "isn't": 0.34; 'print': 0.35; 'header:User-Agent:1': 0.35; 'reply- to:addr:python.org': 0.35; 'but': 0.38; 'to:addr:python.org': 0.39; 'how': 0.39; "it's": 0.40; 'skip:h 20': 0.60; 'subject:about': 0.66; 'reply-to:no real name:2**0': 0.72; 'header :Reply-To:1': 0.72; 'one!': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoIHAG1vsE1UXebj/2dsb2JhbACYBY1Jd4hwu26FdgSSMINn Date: Thu, 21 Apr 2011 19:00:08 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A question about Python Classes References: <2219ee53-e8aa-4ac4-839f-014c3d1b1914@a19g2000prj.googlegroups.com> <87k4enil5g.fsf@kuiper.lan.informatimago.com> In-Reply-To: <87k4enil5g.fsf@kuiper.lan.informatimago.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303408813 news.xs4all.nl 81481 [::ffff:82.94.164.166]:56956 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3815 On 21/04/2011 18:12, Pascal J. Bourguignon wrote: > chad 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! > No, he didn't, he created an instance of HomeHandler. > test is an instance of HomeHandler, which is a subclass of BaseHandler, > so test is also an instance of BaseHandler. > test isn't really an instance of BaseHandler, it's an instance of HomeHandler, which is a subclass of BaseHandler. If you do this: class BaseHandler(object): def foo(self): print "Hello" class HomeHandler(BaseHandler): pass test = HomeHandler() then you'll find: >>> isinstance(test, BaseHandler) True but: >>> type(test)