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
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]pyt...@bdurham.com
To: [2]python-list@python.org
On Mon, Jun 30, 2014 at 11:43 PM, pyt...@bdurham.com wrote:
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
Hi Chris,
Sounds like you want to subclass dict, then. Something like this:
Nice!!!
I need to study your solution, but at first blush it looks exactly like
what I wanted to implement.
Thank you!
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
On 06/30/2014 07:44 AM, pyt...@bdurham.com wrote:
Nice!!!
I need to study your solution, but at first blush it looks exactly like
what I wanted to implement.
Keep in mind that dict /will not/ call your overridden methods, so if, for example, you provide your own __getitem__ you
will also
Ethan,
Keep in mind that dict /will not/ call your overridden methods, so if, for
example, you provide your own __getitem__ you
will also need to provide your own copies of any dict method that calls
__getitem__.
I'm not sure I understand. Are you saying that Chris's __getitem__ will
not be
On 06/30/2014 09:47 AM, pyt...@bdurham.com wrote:
Keep in mind that dict /will not/ call your overridden methods, so if,
for example, you provide your own __getitem__ you will also need to
provide your own copies of any dict method that calls __getitem__.
I'm not sure I understand. Are you
Ethan,
Is this specific to the native Dict class (because its implemented in C vs.
Python?) or is this behavior more general.
I /think/ it's only dict, but I haven't played with subclassing lists,
tuples, etc. It's not a C vs Python issue, but a
'implemented with __private methods'
On Tue, Jul 1, 2014 at 2:47 AM, pyt...@bdurham.com wrote:
I'm not sure I understand. Are you saying that Chris's __getitem__ will
not be called by other dict methods that would normally call this magic
method and instead call the parent's __getitem__ directly (via super()
or something