Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Pavlos Parissis Newsgroups: comp.lang.python Subject: Re: subclassing collections.Counter Date: Tue, 15 Dec 2015 17:20:56 +0100 Lines: 50 Message-ID: References: <567036A5.6050205@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="HoQsqMS4xPD9oSwvdDifoGD49bmPv2Dwj" X-Trace: news.uni-berlin.de NLHTvqUUSBQ0SfX0xfTaSwipa0gNBy5/Y0gSMTnz7EwA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'override': 0.07; 'subject:skip:c 10': 0.07; 'methods,': 0.09; 'metrics': 0.09; 'filename:fname piece:signature': 0.16; 'keys.': 0.16; 'magic': 0.16; 'received:192.168.0.103': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'attribute': 0.18; '2015': 0.20; 'class,': 0.22; 'maintains': 0.22; 'cheers,': 0.22; 'am,': 0.23; 'leave': 0.23; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'values': 0.28; 'extending': 0.29; 'thus,': 0.29; '15,': 0.30; 'extend': 0.31; 'class': 0.33; 'problem': 0.33; 'right?': 0.33; 'message-id:@gmail.com': 0.34; 'tue,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'returning': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'thought': 0.37; 'hi,': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'real': 0.62; 'sum': 0.69; 'average.': 0.91; 'average': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=0eeozCDmDi/Mycw8e7ZR0/MYjkM/feX39t//UnSavwk=; b=qQdxftzG+6QxNNBytr645eS/18RDV5v1en7sNcuBx7CUI1lPaJKsdrbW1oIYOV7IID bsGcVr8UC8W8Zj2wfTgnx6oemVdOu80xPIJRypvkIJg7PpUh0nYwu9/OyVTRRFi9rsZm zTqVHZSQFv0fskBteDRtG/NgHvXy44tGgp6PIF43H7gXC1UJllJj/u9U4lNfHogV+oFh 4q3c08UFKq1K4nwpf0oQWCZt9GcF4vlnXoQasW0GP8PTGmZEvjWTQfhNRMI6/OBjIjuy D/mZu6BV42MS/D2AMKy1SMsOHilEZQoSgIcXVogrIRRmprpytgpboXNzf8xq8lPBI0hY sn9A== X-Received: by 10.28.87.131 with SMTP id l125mr1538320wmb.8.1450196459327; Tue, 15 Dec 2015 08:20:59 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100471 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --HoQsqMS4xPD9oSwvdDifoGD49bmPv2Dwj Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 15/12/2015 05:11 =CE=BC=CE=BC, Ian Kelly wrote: > On Tue, Dec 15, 2015 at 8:49 AM, Pavlos Parissis > 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. >=20 > 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. >=20 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 --HoQsqMS4xPD9oSwvdDifoGD49bmPv2Dwj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWcD3oAAoJEIP8ktofcXa5w4IQAMj+fD3G0zdKWnp8KOenRxQp PGWSwV8jiwwaigwwyBgJlheY2TDCaBNRXVibe4CF8iEV8xy7D26maviQVjsd3fv0 bLZjVmcle/4mqKv7Nj8TGPYdtqWRaa+dOWLyMU31ISM4gI4+dkKdUgTaPMePqAei DaN2ceBJjIWErVeGu6HVQMZ3xELRBTwZgqB/gWVzTxYaGbzhW+MLfSpMSlZCsiej bjb4SObMO3Ptblzd+UpUhYTUL7SgeVm057YY3YOhMkVCrfM4JdJST3P2igPIj2jG VKMOQaDXheSS5HZLL74E2u68BrdnlMrJVM2cWykZZCAqwiGTMOrLnpDmiFOcuiCc ktzZzxFhJnphyKHWgO/Wi+56cP0BqyX041RpwdAXBBQO66Z/5I+ME6PezFzCf7Sk X27piKIhu/+SlI1vgrr9hRT0pLhwERkv4N4dZqqLwm2azArvx5TaDHVIEUcLlE9k zIW7ZxAKcacXtyY46IKlrwV1K8YucSQo77VzPlB2RrV65h+h5bJ8zwyHBqRVgAbj coWH01XQHWpeb7PLk+27/3d6ZmSd5OgWpaZsf2qQepXO1rODaHB4cVvzEVzqCziY g3A62R7+IWtlhijy+lkE5ftP+wwXKf8dBpfUSioRIWocLf8OnfXNoMW/1WLXlXUQ 91FBDvO7Gu+JxMoHa7wR =w7Do -----END PGP SIGNATURE----- --HoQsqMS4xPD9oSwvdDifoGD49bmPv2Dwj--