[Steven D'Aprano]
> But if I try to create a regular dict from this, dict() doesn't call my
> __getitem__ method:
>
> >>> dict(d)
>
> {0: ('a', 'extra_data'), 1: ('b', 'extra_data')}
>
> instead of {0: 'a', 1: 'b'} as I expected.
>
> How can I fix this?
Try using dict(d.items()).
Raymond
--
ht
Steven D'Aprano wrote:
> On Mon, 20 Sep 2010 11:53:48 +, Duncan Booth wrote:
>
>> I was going to suggest overriding items() (or iteritems() for Python
>> 2.x), but while that is another hole that your values leak out it
isn't
>> the hole used by the dict constructor.
>
> Yes, I already ove
Christian Heimes writes:
> Am 20.09.2010 13:11, schrieb Steven D'Aprano:
>> I have a dict subclass that associates extra data with each value of the
>> key/value items:
> [...]
>> How can I fix this?
>
> Since the dict class is crucial to the overall performance of Python,
> the dict class behav
On Mon, 20 Sep 2010 11:53:48 +, Duncan Booth wrote:
> I was going to suggest overriding items() (or iteritems() for Python
> 2.x), but while that is another hole that your values leak out it isn't
> the hole used by the dict constructor.
Yes, I already override items(), keys(), values(), thei
Am 20.09.2010 13:11, schrieb Steven D'Aprano:
> I have a dict subclass that associates extra data with each value of the
> key/value items:
[...]
> How can I fix this?
Since the dict class is crucial to the overall performance of Python,
the dict class behaves bit different than other classes. I
Steven D'Aprano wrote:
> I have a dict subclass that associates extra data with each value of
the
> key/value items:
>
> class MyDict(dict):
> def __setitem__(self, key, value):
> super(MyDict, self).__setitem__(key, (value, "extra_data"))
> def __getitem__(self, key):
>