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 so I wanted to define a new class, based on
Fraction, that includes this new method.
But I am not clear on how to delegate from my new class to
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 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 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
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
&g
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
>
> Sinc
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 implement
On 11/04/2015 03:04, Steven D'Aprano wrote:
> It may be a bit slow for very large numbers. On my computer, this takes 20
> seconds:
>
> py> pyprimes.factors.factorise(2**111+1)
> [3, 3, 1777, 3331, 17539, 25781083, 107775231312019L]
>
>
> but that is the nature of factorising large numbers.
>
On 12/04/2015 15:29, Steven D'Aprano wrote:
>> I don'tknow how well it compares more generally but where large amounts
>> of memory are available a simple sieve works quite well. I have an
>> implementation available here (in Python 3):
>>
>> http://ccgi.gladman.plus.com/wp/?page_id=1500
>
> Um,
On 12/04/2015 18:20, Paul Rubin wrote:
> Steven D'Aprano writes:
>> Um, "simple sieve"? You're using Miller-Rabin to check for candidate
>> prime factors. I don't think that counts as a simple sieve :-)
>
> How does Miller-Rabin help? It has to cost more than trial division.
As we factor the nu
On 24/07/2015 12:04, Chris Angelico wrote:
> On Fri, Jul 24, 2015 at 8:53 PM, Robin Becker wrote:
>> yes I build extensions for reportlab. Unfortunately, despite our MSDN
>> subscription to the Visual Studio stuff we have no access to the Visual
>> Studio Version 2015. Last one in my downloads is
On 08/09/2015 02:35, Larry Hastings wrote:
>
>
> On behalf of the Python development community and the Python 3.5 release
> team, I'm relieved to announce the availability of Python 3.5.0rc3, also
> known as Python 3.5.0 Release Candidate 3.
>
> The next release of Python 3.5 will be Python 3.5.
On 16/10/2015 17:25, Steven D'Aprano wrote:
> Hello folks,
[snip detail]
> randbelow(end):
> return a random integer in the half-open interval 0...end
> (including 0, excluding end)
>
> randint(start, end):
> return a random integer in the closed interval start...end
> (including
13 matches
Mail list logo