Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84537
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Delegation in Python |
| Date | 2015-01-24 20:31 -0500 |
| References | <FeCdnXdsTpunvlnJnZ2dnUVZ8judnZ2d@brightview.co.uk> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18120.1422149503.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 22:57 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 10:22 +1100
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:38 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 10:43 +1100
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 00:18 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 11:28 +1100
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 07:49 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 19:07 +1100
Re: Delegation in Python Gary Herron <gherron@digipen.edu> - 2015-01-24 15:47 -0800
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:58 +0000
Re: Delegation in Python Gary Herron <gherron@digipen.edu> - 2015-01-24 15:41 -0800
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:52 +0000
Re: Delegation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-24 23:59 +0000
Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 11:07 +1100
Re: Delegation in Python Terry Reedy <tjreedy@udel.edu> - 2015-01-24 20:31 -0500
Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 07:43 +0000
csiph-web