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: 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" Date: Wed, 24 Aug 2011 21:09:28 +1000 From: John O'Hagan 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: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, 23 Aug 2011 17:25:22 +1000 Steven D'Aprano 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 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