Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Kyle T. Jones" Newsgroups: comp.lang.python Subject: Re: A question about Python Classes Date: Fri, 22 Apr 2011 08:49:07 -0500 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: <2219ee53-e8aa-4ac4-839f-014c3d1b1914@a19g2000prj.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 22 Apr 2011 13:48:48 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="jmWGAqTnn4Bqgg9eOxho6Q"; logging-data="11278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NOuGNuwmPKRSt2hfXjCAG5RgwjHJ6BGc=" User-Agent: Thunderbird 2.0.0.24 (X11/20101027) In-Reply-To: Cancel-Lock: sha1:76rimUTR6YZYdRBiwRDqK2Nlru4= Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3866 Ethan Furman 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? > > You don't need to create an instance of BaseHandler. You have the > class, Python knows you have the class -- Python will look there if the > subclasses lack an attribute. > > ~Ethan~ > Really? That's not at all how I thought it worked in Python (post-instantiation referencing of class and superclass code...) Cheers.