Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12058
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <johnmohagan@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.122 |
| X-Spam-Level | * |
| X-Spam-Evidence | '*H*': 0.76; '*S*': 0.00; 'def': 0.15; 'name)': 0.16; 'name):': 0.16; 'mon,': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'defined': 0.19; 'header:In-Reply-To:1': 0.22; 'happen.': 0.23; 'received:209.85.213.46': 0.23; 'received:mail- yw0-f46.google.com': 0.23; "shouldn't": 0.23; 'aug': 0.24; 'sender:addr:gmail.com': 0.25; 'raise': 0.28; 'looks': 0.29; 'thanks': 0.30; 'class': 0.30; 'generally': 0.32; "isn't": 0.33; 'to:addr:python-list': 0.33; 'however,': 0.34; '...': 0.34; 'charset:us-ascii': 0.36; 'something': 0.37; 'steven': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'header:Mime- Version:1': 0.39; 'to:addr:python.org': 0.39; 'subject:from': 0.40; 'header:Message-Id:1': 0.61; 'john': 0.62; 'back': 0.62; 'fall': 0.64; 'super': 0.64; 'subject:without': 0.67; 'doing.': 0.73; 'subject:class': 0.84; 'received:home': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:content-transfer-encoding; bh=EQqKv5uhsqoMMt5PmErlLVh8+7NT0a0em2mCJp9KdhI=; b=vhPNRj3dskjYHQHHK7e03Txetyi4B/IuyvxXvOcl8BKA4ZLb0bxKKziEaS0hUVzujh TBrcOLIghzZfrL7qfaFsGepBvXO7sRuxHV8SAa4r91Wturkv+SM034oE7ry1De30XknI OdReKFmm5DF5C1FjLgv4EddzBBQo4JPA8XZ9I= |
| Sender | "John O'Hagan" <johnmohagan@gmail.com> |
| Date | Tue, 23 Aug 2011 10:55:26 +1000 |
| From | John O'Hagan <research@johnohagan.com> |
| To | python-list@python.org |
| Subject | Re: Adding modified methods from another class without subclassing |
| In-Reply-To | <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> |
| References | <mailman.301.1313989495.27778.python-list@python.org> <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> |
| X-Mailer | Sylpheed 3.2.0beta1 (GTK+ 2.24.4; x86_64-pc-linux-gnu) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| 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.335.1314060935.27778.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1314060935 news.xs4all.nl 23878 [2001:888:2000:d::a6]:39575 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12058 |
Show key headers only | View raw
On Mon, 22 Aug 2011 23:08:50 +1000
John O'Hagan <research@johnohagan.com> wrote:
> On Mon, 22 Aug 2011 15:27:36 +1000
> Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
[..]
> > Looks like a call for (semi-)automatic delegation!
> >
> > Try something like this:
> >
> >
> > # Untested
> > class MySeq(object):
> > methods_to_delegate = ('__getitem__', '__len__', ...)
> > pitches = ... # make sure pitches is defined
> > def __getattr__(self, name):
> > if name in self.__class__.methods_to_delegate:
> > return getattr(self.pitches, name)
> > return super(MySeq, object).__getattr__(self, name)
> > # will likely raise AttributeError
>
[..]
>
> However, I don't understand what the super call is doing. If the method isn't delegated, shouldn't it just fall back to getattr(self, name)?
On reading the __getattr__ docs properly, I see that AttributeError is what should generally happen.
> Thanks and regards,
>
> John
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Adding modified methods from another class without subclassing John O'Hagan <research@johnohagan.com> - 2011-08-22 15:04 +1000
Re: Adding modified methods from another class without subclassing Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-22 15:27 +1000
Re: Adding modified methods from another class without subclassing John O'Hagan <research@johnohagan.com> - 2011-08-22 23:08 +1000
Re: Adding modified methods from another class without subclassing Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-23 17:25 +1000
Re: Adding modified methods from another class without subclassing John O'Hagan <research@johnohagan.com> - 2011-08-24 21:09 +1000
Re: Adding modified methods from another class without subclassing John O'Hagan <research@johnohagan.com> - 2011-08-23 10:55 +1000
Re: Adding modified methods from another class without subclassing Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-23 13:26 +1000
csiph-web