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


Groups > comp.lang.python > #15111

Re: How to mix-in __getattr__ after the fact?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <malaclypse2@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'oct': 0.02; 'instance': 0.05; 'attribute': 0.07; 'python': 0.08; 'called.': 0.09; 'interpreter.': 0.09; 'class,': 0.15; 'somehow,': 0.16; 'wrote:': 0.16; 'received:209.85.210.174': 0.18; 'received:mail- iy0-f174.google.com': 0.18; 'seems': 0.20; 'figure': 0.21; 'header :In-Reply-To:1': 0.22; 'mix': 0.23; 'pm,': 0.24; 'skip:b 20': 0.26; '(see': 0.28; 'bound': 0.29; 'looks': 0.29; 'message- id:@mail.gmail.com': 0.29; 'class': 0.30; 'subject:?': 0.31; 'seem': 0.31; 'does': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; 'object': 0.35; 'subject:How': 0.35; 'url:python': 0.36; 'fri,': 0.36; 'doing': 0.36; 'but': 0.37; 'something': 0.37; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'minutes': 0.64; 'ready': 0.65; 'special': 0.67; 'url:datamodel': 0.84; 'url:reference': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=L+BvZ3axhcc8h3bOO2HlfRoOkfPoMvimCsg/ImqJgT0=; b=d7dRX5RHRnii9gipSBKOEC7Wihi1Xuv2sO6VzZ014gYPRogres26uaIHw71bnFvfKX feq9bRW9h8GEHA9czRn81t3THlWobihIL/xsZ8q/lmSRhV4e4epSE0+xydGfQKo2N8zk PMEMBlRLNwdHqKdwcwwwnHUht56Sf6Xjrkk9U=
MIME-Version 1.0
In-Reply-To <4630c4d0-86bc-4295-8bbb-6f58415191c8@v15g2000vbm.googlegroups.com>
References <4630c4d0-86bc-4295-8bbb-6f58415191c8@v15g2000vbm.googlegroups.com>
Date Fri, 28 Oct 2011 14:14:34 -0400
Subject Re: How to mix-in __getattr__ after the fact?
From Jerry Hill <malaclypse2@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=UTF-8
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.2289.1319825678.27778.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1319825678 news.xs4all.nl 6976 [2001:888:2000:d::a6]:42317
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15111

Show key headers only | View raw


On Fri, Oct 28, 2011 at 1:34 PM, dhyams <dhyams@gmail.com> wrote:
> If I call __getattr__ directly, as in bessie.__getattr__('foo'), it
> works as it should obviously; so the method is bound and ready to be
> called.  But Python does not seem to want to call __getattr__
> appropriately if I mix it in after the object is already created.  Is
> there a workaround, or am I doing something wrongly?

Python looks up special methods on the class, not the instance (see
http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes).

It seems like you ought to be able to delegate the special attribute
access from the class to the instance somehow, but I couldn't figure
out how to do it in a few minutes of fiddling at the interpreter.

-- 
Jerry

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to mix-in __getattr__ after the fact? dhyams <dhyams@gmail.com> - 2011-10-28 10:34 -0700
  Re: How to mix-in __getattr__ after the fact? Jerry Hill <malaclypse2@gmail.com> - 2011-10-28 14:14 -0400
  Re: How to mix-in __getattr__ after the fact? Ethan Furman <ethan@stoneleaf.us> - 2011-10-28 11:20 -0700
  Re: How to mix-in __getattr__ after the fact? Lie Ryan <lie.1296@gmail.com> - 2011-10-29 13:26 +1100
    Re: How to mix-in __getattr__ after the fact? dhyams <dhyams@gmail.com> - 2011-10-31 05:01 -0700
      Re: How to mix-in __getattr__ after the fact? DevPlayer <devplayer@gmail.com> - 2011-11-01 22:50 -0700
      Re: How to mix-in __getattr__ after the fact? Lie Ryan <lie.1296@gmail.com> - 2011-11-08 15:17 +1100
        Re: How to mix-in __getattr__ after the fact? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-08 05:58 +0000
      Re: How to mix-in __getattr__ after the fact? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-11-08 11:21 +0100

csiph-web