Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:Python': 0.06; 'class,': 0.07; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; "python's": 0.19; '(in': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'handling': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'resolution': 0.29; 'am,': 0.29; 'nature': 0.30; 'message- id:@mail.gmail.com': 0.30; '25,': 0.31; 'exceptions': 0.31; 'url:06': 0.31; 'class': 0.32; 'this.': 0.32; 'another': 0.32; 'brian': 0.33; 'info': 0.35; 'case,': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'web,': 0.36; 'thanks': 0.36; 'searching': 0.37; 'called': 0.40; 'url:blogspot': 0.65; '2015': 0.84; 'delegation': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Y8695SPrriRB98HZuR+X7EH5xt76BgsL+EFuUvZk/TU=; b=kODfhgquwup1uNPqtNA46REzgnDo6c15eS2/P18lG9VLywkMF+hgs1lLjCzr/QLiJc +AODio239DDXg9fdPRjbKl8NXZHZ2QBXpaQDaOwskxPaVfmjk34l0X0MIz8IyAk7EIEq 4MXkk+BZDu9c90ZNR1udyC5hR1gBpVh+SYLfIy2dAIZxZsoMbO5Ovd3DVpCMT1PZVLcq UQBbCVVJBog61b6vPb6cVbFxvBCvM98XS1mFw5AhGuj3AOpt/SdYItUMMQZ7JBwhaBpq 74EwuYeaYcrw4DVL+shU9fXzhtRKSAec/vAWKoEIXwCMejdpav57lihr3QLGMEjRuK66 xMaA== MIME-Version: 1.0 X-Received: by 10.224.46.132 with SMTP id j4mr8247338qaf.16.1422143013186; Sat, 24 Jan 2015 15:43:33 -0800 (PST) In-Reply-To: <5ZKdnd6rbdZ3sVnJnZ2dnUVZ8mCdnZ2d@brightview.co.uk> References: <5ZKdnd6rbdZ3sVnJnZ2dnUVZ8mCdnZ2d@brightview.co.uk> Date: Sun, 25 Jan 2015 10:43:33 +1100 Subject: Re: Delegation in Python From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422143020 news.xs4all.nl 2852 [2001:888:2000:d::a6]:40442 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84519 On Sun, Jan 25, 2015 at 10:38 AM, Brian Gladman wrote: > On 24/01/2015 23:22, Chris Angelico wrote: >> class RF(Fraction): >> def is_integer(self): >> return self.numerator % self.denominator == 0 > > Thanks for your help on this. I must admit that nowhere in a lot of > searching did I find that delegation is achieved by doing nothing! Hehe :) If you want a technical look at it, what you have is the fundamental nature of subclassing: you derive from another class, and your class is identical to that with certain exceptions (in your case, an additional method). Python's way of handling that is called the Method Resolution Order or MRO, and you can find info on it on the web, eg: http://python-history.blogspot.com/2010/06/method-resolution-order.html Enjoy! ChrisA