Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100471

Re: subclassing collections.Counter

From Pavlos Parissis <pavlos.parissis@gmail.com>
Newsgroups comp.lang.python
Subject Re: subclassing collections.Counter
Date 2015-12-15 17:20 +0100
Message-ID <mailman.31.1450196467.22044.python-list@python.org> (permalink)
References <567036A5.6050205@gmail.com> <CALwzidnifp20WayShDXTGJ-PxdCk0LeZVb-o9fTQzFCN6i1dUQ@mail.gmail.com>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 15/12/2015 05:11 μμ, Ian Kelly wrote:
> On Tue, Dec 15, 2015 at 8:49 AM, Pavlos Parissis
> <pavlos.parissis@gmail.com> wrote:
>> Hi,
>>
>> I need to store values for metrics and return the average for some
>> and the sum for the rest. Thus, I thought I could extend
>> collections.Counter class by returning averages for some keys.
> 
> Leave Counter out of it, as this is not what it's designed for. Write
> a custom Metrics class, with each attribute being a pseudo-collection
> that maintains a sum or average.
> 

But then I will have to override a lot of magic methods, right?
What is the real problem of extending Counter in the way I did?

Cheers,
Pavlos

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: subclassing collections.Counter Pavlos Parissis <pavlos.parissis@gmail.com> - 2015-12-15 17:20 +0100

csiph-web