Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.06; '*not*': 0.07; 'class,': 0.07; 'float': 0.07; 'method.': 0.07; 'function,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terms,': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'java.': 0.16; 'overriding': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'implementing': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'fraction': 0.24; 'integer': 0.24; 'math': 0.24; 'define': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'leave': 0.29; 'reduced': 0.31; 'brian': 0.33; 'advice': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'method': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'new': 0.61; 'worth': 0.66; 'lowest': 0.74; 'special': 0.74; 'received:fios.verizon.net': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Delegation in Python Date: Sat, 24 Jan 2015 20:31:31 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422149503 news.xs4all.nl 2878 [2001:888:2000:d::a6]:44791 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84537 On 1/24/2015 5:57 PM, Brian Gladman wrote: > I would appreciate advice on how to set up delgation in Python. > > I am continuously implementing a function to test whether a Python > Fraction is an integer Since Fractions are reduced to lowest terms, >>> from fractions import Fraction as F >>> F(4, 2) Fraction(2, 1) >>> F(12, 3) Fraction(4, 1) the test is that the denominator is 1 >>> F(12,3).denominator == 1 True >>> F(12,5).denominator == 1 False it may not be worth the bother to define a function, def fint(F): return F.denominator == 1 >so I wanted to define a new class, based on > Fraction, that includes this new method. but if you do, there is little need to make it a method. You are not overriding an existing method or adding a new special method. The math module has float and int functions that have *not* been turned into methods. Ditto for cmath. I would just leave the function a function. Python is not Java. -- Terry Jan Reedy