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


Groups > comp.lang.python > #3890

Re: A question about Python Classes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <pavlovevidence@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.04; 'instance': 0.05; 'pascal': 0.07; 'python': 0.07; '21,': 0.09; 'instance.': 0.09; 'subclass': 0.09; 'usage.': 0.09; 'def': 0.13; 'wrote:': 0.14; '"proper': 0.16; 'chad': 0.16; "didn't,": 0.16; 'mrab': 0.16; 'subject:Classes': 0.16; 'suggest': 0.19; 'writes:': 0.20; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'language': 0.20; 'not.': 0.22; 'header:In-Reply-To:1': 0.22; 'subject:question': 0.22; 'cc:addr:python-list': 0.22; 'incorrect': 0.23; "i'm": 0.26; 'object': 0.27; 'pass': 0.27; 'class': 0.29; 'cc:addr:python.org': 0.31; 'carl': 0.31; 'does': 0.31; 'vote': 0.33; 'created': 0.33; 'test': 0.33; "isn't": 0.34; 'print': 0.35; 'header:User-Agent:1': 0.35; 'received:209.85': 0.37; 'thursday,': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'received:209': 0.39; 'how': 0.39; 'would': 0.40; "it's": 0.40; 'skip:h 20': 0.60; '2011': 0.62; 'subject:about': 0.66; 'to:addr:googlegroups.com': 0.69; 'reply-to:no real name:2**0': 0.72; 'header:Reply-To:1': 0.72; 'one!': 0.84; 'received:209.85.210.56': 0.91; 'received:mail- pz0-f56.google.com': 0.91; 'reply-to:addr:googlegroups.com': 0.93
Newsgroups comp.lang.python
Date Fri, 22 Apr 2011 12:47:02 -0700 (PDT)
In-Reply-To <mailman.715.1303408813.9059.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=157.127.155.214; posting-account=XFEWnwoAAADNO10m3Wcmq_SWdmyZuXff
User-Agent G2/1.0
MIME-Version 1.0
Subject Re: A question about Python Classes
From Carl Banks <pavlovevidence@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To comp.lang.python@googlegroups.com
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>
Message-ID <mailman.763.1303501625.9059.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 82.94.164.166
X-Trace 1303501625 news.xs4all.nl 81476 [::ffff:82.94.164.166]:40055
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3890

Show key headers only | View raw


On Thursday, April 21, 2011 11:00:08 AM UTC-7, MRAB wrote:
> On 21/04/2011 18:12, Pascal J. Bourguignon wrote:
> > chad<cda...@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!
> >
> 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.

I'm going to vote that this is incorrect usage.  An instance of HomeHandler is also an instance of BaseHandler, and it is incorrect to say it is not.  The call to HomeHandler does create an instance of BaseHandler.

The Python language itself validates this usage.  isinstance(test,BaseHandler) returns True.


If you are looking for a term to indicate an object for which type(test) == BaseHandler, then I would suggest "proper instance".  test is an instance of BaseHandler, but it is not a proper instance.


Carl Banks

Back to comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Re: A question about Python Classes Carl Banks <pavlovevidence@gmail.com> - 2011-04-22 12:47 -0700
  Re: A question about Python Classes chad <cdalten@gmail.com> - 2011-04-23 13:30 -0700
    Re: A question about Python Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-24 00:03 +0000

csiph-web