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


Groups > comp.lang.python > #73748

Re: Creating a dict-like class that counts successful and failed key matches

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@bdurham.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'matches': 0.07; 'modified': 0.07; 'tool,': 0.07; 'key.': 0.09; 'keys,': 0.09; 'methods,': 0.09; 'override': 0.09; 'received:internal': 0.09; 'count,': 0.16; 'diagnostic': 0.16; 'dict': 0.16; 'from:addr:python': 0.16; 'goal,': 0.16; 'magic': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'processes.': 0.16; 'raised.': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.44': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:compute4.internal': 0.16; 'received:messagingengine.com': 0.16; 'retrieving': 0.16; 'subclass': 0.16; 'subject: \n ': 0.16; 'subject:class': 0.16; 'subject:failed': 0.16; 'subject:key': 0.16; 'userdict': 0.16; 'exception': 0.16; 'basically': 0.19; 'creating': 0.23; 'subject:like': 0.24; 'mon,': 0.24; 'looks': 0.24; "i've": 0.25; 'options': 0.25; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'returned': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'keys': 0.31; 'subject:that': 0.31; 'class': 0.32; 'covered': 0.32; 'regular': 0.32; "we're": 0.32; 'another': 0.32; 'url:python': 0.33; '-----': 0.33; 'date:': 0.34; 'sense': 0.34; "i'd": 0.34; 'received:66': 0.35; 'common': 0.35; 'beyond': 0.35; 'curious': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'should': 0.36; 'email addr:python.org': 0.37; 'received:10': 0.37; 'implement': 0.38; 'thank': 0.38; 'to:addr :python-list': 0.38; 'anything': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'even': 0.60; 'from:no real name:2**0': 0.61; 'tracking': 0.61; 'header :Message-Id:1': 0.63; 'high': 0.63; 'offering': 0.63; 'our': 0.64; 'provide': 0.64; 'more': 0.64; 'total': 0.65; 'email name:python- list': 0.65; 'hints': 0.68; 'research,': 0.68; 'default': 0.69; 'counts': 0.83; 'dict,': 0.84; 'items,': 0.91
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=bdurham.com; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= fRld7q7eFyQQ7Z8e1h2UaRXLmRU=; b=kpjjIfAkyw5Wc5/sHv4hP4h/u8GBqlN4 7BdppJirGB9wMfcWzTThvg7oTHYuB6zUxjcyiC8RpFKMA72II/cllw5JUYd8NLsp Fq7LWueaWBE9+0+Vqz87iv7kpuK3HT7aB++emPugiwZ+HKW+i34lWfnwgkYA0ZEN Z/rai0ZOAhw=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=fRld7q7eFyQQ7Z8e1h2UaRXLmRU=; b=dn7 gZgdvBzRGySUzmsZ1uExuUuVqAVyepBluuUZMCeMj9Ajh/3wkwl5MI66MMimK1ta IsFrVCxVgiJcScRQDlZlLYaxg39T410beUJ3JuAq9WqgEnCuxB0O7Yg3qm/eJVGK 8ffYKt4fJCm4rcVgS5eumuq0aH85tQ+4T7b53UQw=
X-Sasl-Enc LAhQD+BUlNn8wN3dcEe8w/4mqfotK5bFWSr3F31cpJaR 1404137417
From python@bdurham.com
To python-list@python.org
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Content-Type multipart/alternative; boundary="_----------=_1404137417174662"; charset="utf-8"
X-Mailer MessagingEngine.com Webmail Interface - ajax-988f1f18
In-Reply-To <1404135829.10485.136092537.2F0486D2@webmail.messagingengine.com>
References <1404135829.10485.136092537.2F0486D2@webmail.messagingengine.com>
Subject Re: Creating a dict-like class that counts successful and failed key matches
Date Mon, 30 Jun 2014 10:10:17 -0400
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11343.1404137422.18130.python-list@python.org> (permalink)
Lines 120
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404137422 news.xs4all.nl 2901 [2001:888:2000:d::a6]:39700
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73748

Show key headers only | View raw


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

After some additional research, it looks like I may have even
more options to consider including using a UserDict mixin.



I think I've identified another magic method to subclass ...
__missing__.





----- Original message -----

From: [1]python@bdurham.com

To: [2]python-list@python.org

Subject: Creating a dict-like class that counts successful and
failed key matches

Date: Mon, 30 Jun 2014 09:43:49 -0400



As a diagnostic tool, I would like to create a dict-like class
that counts successful and failed key matches by key. By failed
I mean in the sense that a default value was returned vs. an
exception raised. By count, I mean by tracking counts for
individual keys vs. just total success/failure counts. The
class needs to support setting values, retrieving values, and
retrieving keys, items, and key/item pairs. Basically anything
that a regular dict, I'd like my modified class to do as well.



Use case: I'm curious to see what key's we're missing that our
code is using default to provide and I'm also interested in
looking at our high frequency keys as a way to double check our
processes.



Is this a common pattern covered by the standard lib (I don't
see anything in collections)?



I'm looking for ideas on how to implement ... as a subclass of
Dict, as a duck-like class offering Dict like methods, other?



I'm also looking for some hints on what magic methods I should
override to accomplish my goal, eg. beyond __getitem__.



Thank you,

Malcolm



--

[3]https://mail.python.org/mailman/listinfo/python-list

References

1. mailto:python@bdurham.com
2. mailto:python-list@python.org
3. https://mail.python.org/mailman/listinfo/python-list

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


Thread

Re: Creating a dict-like class that counts successful and failed key matches python@bdurham.com - 2014-06-30 10:10 -0400

csiph-web