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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, Oct 28, 2011 at 1:34 PM, dhyams 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. =C2=A0But Python does not seem to want to call __getattr__ > appropriately if I mix it in after the object is already created. =C2=A0I= s > 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-n= ew-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. --=20 Jerry