Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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; 'help?': 0.03; 'subject:Python': 0.04; 'instance': 0.05; '3.2': 0.07; 'python': 0.07; 'attribute.': 0.09; 'foo': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'jones': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:74.54.199': 0.09; 'received:74.54.199.50': 0.09; 'received:gator410.hostgator.com': 0.09; 'referencing': 0.09; 'subclasses': 0.09; '~ethan~': 0.09; '>>>': 0.12; 'def': 0.13; 'wrote:': 0.14; 'chad': 0.16; 'furman': 0.16; 'here!")': 0.16; 'really?': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:Classes': 0.16; 'class,': 0.16; 'header:In-Reply-To:1': 0.22; 'subject:question': 0.22; 'worked': 0.24; "i'm": 0.26; 'pass': 0.27; 'class': 0.29; 'does': 0.31; 'to:addr:python-list': 0.32; 'skip:e 20': 0.33; 'created': 0.33; 'test': 0.33; 'there': 0.35; 'print': 0.35; 'header:User-Agent:1': 0.35; 'exactly': 0.37; 'but': 0.38; 'to:addr:python.org': 0.39; 'how': 0.39; 'header:Received:5': 0.40; 'received:74.54': 0.60; 'skip:h 20': 0.60; 'received:hostgator.com': 0.64; 'subject:about': 0.66; 'received:websitewelcome.com': 0.71; 'received:gateway16.websitewelcome.com': 0.84; 'received:69.93': 0.91 Date: Fri, 22 Apr 2011 12:38:21 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2234 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list 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: 63 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303500424 news.xs4all.nl 81481 [::ffff:82.94.164.166]:35523 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3886 Kyle T. Jones wrote: > 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...) I'm not sure exactly what you're asking/stating, but does this help? 8<---Py 3.2 code------------------------------------------ class BaseClass(): def bFoo(self): print("Base foo here!") class NormalClass(BaseClass): def nFoo(self): print("Normal foo here.") class EnhancedClass(NormalClass): def eFoo(self): print("Enhanced foo comin' at ya!") class EnrichedClass(EnhancedClass): def rFoo(self): print("Am I glowing yet?") test = EnrichedClass() test.bFoo() test.nFoo() test.eFoo() test.rFoo() def newFoo(self): print("Ha! You've been replaced!") BaseClass.bFoo = newFoo test.bFoo() 8<----------------------------------------------------------