subclassing collections.Counter

Pavlos Parissis pavlos.parissis at gmail.com
Tue Dec 15 11:20:56 EST 2015


On 15/12/2015 05:11 μμ, Ian Kelly wrote:
> On Tue, Dec 15, 2015 at 8:49 AM, Pavlos Parissis
> <pavlos.parissis at 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20151215/3e9d86fd/attachment.sig>


More information about the Python-list mailing list