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


Groups > comp.lang.python > #73748 > unrolled thread

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

Started bypython@bdurham.com
First post2014-06-30 10:10 -0400
Last post2014-06-30 10:10 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

Frompython@bdurham.com
Date2014-06-30 10:10 -0400
SubjectRe: Creating a dict-like class that counts successful and failed key matches
Message-ID<mailman.11343.1404137422.18130.python-list@python.org>

[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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web