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


Groups > comp.lang.python > #12139

Re: Adding modified methods from another class without subclassing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.047
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'received:209.85.160.174': 0.09; 'received:mail-gy0-f174.google.com': 0.09; 'def': 0.15; 'mean,': 0.16; 'name)': 0.16; 'name):': 0.16; 'pointers,': 0.16; 'mon,': 0.16; 'wrote:': 0.16; 'modified': 0.18; 'defined': 0.19; 'suggest': 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'tue,': 0.23; 'aug': 0.24; 'sender:addr:gmail.com': 0.25; 'function': 0.27; 'work.': 0.27; 'raise': 0.28; '(maybe': 0.30; 'thanks': 0.30; 'class': 0.30; 'list': 0.32; 'to:addr:python- list': 0.33; '...': 0.34; "i'll": 0.34; 'rather': 0.35; 'received:209.85.160': 0.35; 'reference': 0.35; 'post': 0.36; 'charset:us-ascii': 0.36; 'class.': 0.37; 'steven': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'ways': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'subject:from': 0.40; 'your': 0.61; 'header:Message-Id:1': 0.61; 'john': 0.62; 'back': 0.62; 'subject:without': 0.67; '11:08': 0.84; '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=DWeTrcBQ8+wqWv7LmE9xndJKqai7kKLKIG/wwEboiCY=; b=oIMH5GcpBIVw0lhvSROiGW7z8BTcZYwinxb6zne7rZyPuMl7G/787PvHNaQg4nT3X2 ybzEolR2yKcx1bYF6gHvJSA/+H8Wf0209vjsJrTCt0VJKxS7hy0hh7oJXn4UWEsjGjDY zIUYHR7a525W57JBxaqiJqfjSMlpqSdhzUerU=
Sender "John O'Hagan" <johnmohagan@gmail.com>
Date Wed, 24 Aug 2011 21:09:28 +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 <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com>
References <mailman.301.1313989495.27778.python-list@python.org> <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <mailman.314.1314018545.27778.python-list@python.org> <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.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.385.1314184178.27778.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1314184178 news.xs4all.nl 23857 [2001:888:2000:d::a6]:50637
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12139

Show key headers only | View raw


On Tue, 23 Aug 2011 17:25:22 +1000
Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:

> On Mon, 22 Aug 2011 11:08 pm John O'Hagan wrote:
> 
> > On Mon, 22 Aug 2011 15:27:36 +1000
> > Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> [...]
> >> # 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
> > 
[...]
> 
> > Also, it doesn't immediately suggest to me a way of modifying method calls
> > (maybe __setattr__?). 
> 
> What do you mean, "modifying method calls"?

That was a rather badly-worded reference to a function in my original post which modified the action of list methods in ways specific to the new class. As I said, I re-read the docs on __getattr__, and now __setattr__, and I get what they do now.

Thanks for your pointers, I'll get back to work.

Regards,

John

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


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