On Sun, Jan 25, 2015 at 6:49 PM, Brian Gladman wrote:
> Thanks, a part of this was a wish to understand how to map what I can do
> in other languages into Python. I felt that it might just be possible
> in Python to avoid having to wrap all the methods of the base class in
> the derived class. B
On 25/01/2015 00:28, Chris Angelico wrote:
> On Sun, Jan 25, 2015 at 11:18 AM, Brian Gladman wrote:
>> Is there a way of doing delegation rather than sub-classing?
>>
>> That is, can I create a class (say RF) that passes some of its methods
>> to Fraction for implementation but always returns an R
On 25/01/2015 01:31, Terry Reedy wrote:
> 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
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)
On Sun, Jan 25, 2015 at 11:18 AM, Brian Gladman wrote:
> Is there a way of doing delegation rather than sub-classing?
>
> That is, can I create a class (say RF) that passes some of its methods
> to Fraction for implementation but always returns an RF?
Hmm. The key here is that you want more than
On 24/01/2015 23:43, Chris Angelico wrote:
> 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 mu
On Sun, Jan 25, 2015 at 10:59 AM, Mark Lawrence wrote:
>> You can always "monkey-path" the Fraction class on the fly to add a new
>> method to it. I think most would consider this a bad idea, but it does
>> work.
>
> As regards this being a bad idea I'd suggest the latest score is
> Practicality
On 24/01/2015 23:47, Gary Herron wrote:
> On 01/24/2015 03:38 PM, 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 n
On 24/01/2015 23:41, Gary Herron wrote:
On 01/24/2015 03:22 PM, Chris Angelico wrote:
On Sun, Jan 25, 2015 at 9:57 AM, Brian Gladman wrote:
But I am not clear on how to delegate from my new class to the existing
Fraction class. This is what I have:
--
class RF(Fractio
On 24/01/2015 23:41, Gary Herron wrote:
[snip]>
> You can always "monkey-path" the Fraction class on the fly to add a new
> method to it. I think most would consider this a bad idea, but it does
> work.
> Try this:
>
from fractions import Fraction
def is_integer(self):
> ... return
On 01/24/2015 03:38 PM, 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
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
On 01/24/2015 03:22 PM, Chris Angelico wrote:
On Sun, Jan 25, 2015 at 9:57 AM, Brian Gladman wrote:
But I am not clear on how to delegate from my new class to the existing
Fraction class. This is what I have:
--
class RF(Fraction):
def __new__(self, x, y):
sup
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!
Brian
-
On Sun, Jan 25, 2015 at 9:57 AM, Brian Gladman wrote:
> But I am not clear on how to delegate from my new class to the existing
> Fraction class. This is what I have:
>
> --
> class RF(Fraction):
>
> def __new__(self, x, y):
> super().__new__(self, x, y)
>
> def is
15 matches
Mail list logo