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


Groups > comp.lang.python > #3888

Re: A question about Python Classes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
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; 'python': 0.07; 'attribute': 0.09; 'attribute.': 0.09; 'jones': 0.09; 'referencing': 0.09; 'subclasses': 0.09; '~ethan~': 0.09; '>>>': 0.12; 'am,': 0.14; 'wrote:': 0.14; 'instantiated': 0.16; 'really?': 0.16; 'subject:Classes': 0.16; 'test()': 0.16; '\xa0you': 0.16; 'class,': 0.16; 'tree': 0.20; 'header:In-Reply-To:1': 0.22; 'subject:question': 0.22; 'worked': 0.24; 'received:209.85.161.46': 0.26; 'received:mail- fx0-f46.google.com': 0.26; 'pass': 0.27; 'message- id:@mail.gmail.com': 0.28; 'looks': 0.28; 'received:209.85.161': 0.29; 'fri,': 0.29; 'class': 0.29; 'to:addr:python-list': 0.32; 'there': 0.35; 'received:209.85': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'how': 0.39; "it's": 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'subject:about': 0.66; 'so:': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=pTMJg46LO/xjccXm4nrxkJHIfn/te0kYKqKHlWVjsss=; b=nELrdq0APN4zd96OorXJ44pbMK7Rg6Pd8ht95kwYO2SidWyVGVTH6UZn4Vcw1S3eVX 3WR1f8WSOdLgurY3/yLhCfbPTmx2+b6QNWale+ULtfEF5jpKjYfkavVlNvSRIk/U8DEd L7pphragUJmoV0Bmfm2BG5P6oHpJ9iXYER3ks=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=B/AHvM1+LJi4/gPBa/q0uRXV5Qv4XRNn9O+Nq0UmXGDmkJDxCYIyYxLaIq6LmS1JeP BeGkVOOWEtuaKvtWute0UAVV5j9kO6v5euHZFF34bNVzpDM2y0ko+HnHYyGp9qI3dpve gc2VXyc6xyc2flVwDbvfL8AOI18zBcsaCWg1A=
MIME-Version 1.0
In-Reply-To <ios100$b0e$2@dont-email.me>
References <2219ee53-e8aa-4ac4-839f-014c3d1b1914@a19g2000prj.googlegroups.com> <mailman.716.1303410257.9059.python-list@python.org> <ios100$b0e$2@dont-email.me>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 22 Apr 2011 13:40:59 -0600
Subject Re: A question about Python Classes
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
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.762.1303501291.9059.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 82.94.164.166
X-Trace 1303501291 news.xs4all.nl 41102 [::ffff:82.94.164.166]:50013
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3888

Show key headers only | View raw


On Fri, Apr 22, 2011 at 7:49 AM, Kyle T. Jones
<onexpadREMOVE@evomeryahoodotyouknow.com> wrote:
>> 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...)

Yes, it looks up the attribute in the superclass tree at the time that
it's referenced, not at the time it's instantiated or at the time the
class is created.  So:

>>> class Base(object):
...     x = 5
...
>>> class Test(Base):
...     pass
...
>>> t = Test()
>>> t.x
5
>>> Test.x = 42
>>> t.x
42
>>> Base.x = 7
>>> del Test.x
>>> t.x
7

Or were you talking about something else?

Back to comp.lang.python | Previous | NextPrevious 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