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


Groups > comp.lang.python > #3886

Re: A question about Python Classes

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 <ethan@stoneleaf.us>
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 <ethan@stoneleaf.us>
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> <mailman.716.1303410257.9059.python-list@python.org> <ios100$b0e$2@dont-email.me>
In-Reply-To <ios100$b0e$2@dont-email.me>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.760.1303500423.9059.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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 Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-04-21 18:30 +0200
    Re: A question about Python Classes chad <cdalten@gmail.com> - 2011-04-21 09:46 -0700
  Re: A question about Python Classes "Pascal J. Bourguignon" <pjb@informatimago.com> - 2011-04-21 19:12 +0200
    Re: A question about Python Classes MRAB <python@mrabarnett.plus.com> - 2011-04-21 19:00 +0100
      Re: A question about Python Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-22 01:53 +0000
    Re: A question about Python Classes Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-04-22 11:47 +0200
  Re: A question about Python Classes Terry Reedy <tjreedy@udel.edu> - 2011-04-21 13:39 -0400
  Re: A question about Python Classes Ethan Furman <ethan@stoneleaf.us> - 2011-04-21 11:34 -0700
    Re: A question about Python Classes "Kyle T. Jones" <onexpadREMOVE@EVOMERyahoodotyouknow.com> - 2011-04-22 08:49 -0500
      Re: A question about Python Classes Ethan Furman <ethan@stoneleaf.us> - 2011-04-22 12:38 -0700
      Re: A question about Python Classes Ian Kelly <ian.g.kelly@gmail.com> - 2011-04-22 13:40 -0600

csiph-web