<div class="gmail_quote">On 21 August 2012 14:50, Massimo Di Pierro <span dir="ltr"><<a href="mailto:massimo.dipierro@gmail.com" target="_blank">massimo.dipierro@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello Oscar,<br>
<br>
thanks for your help but your proposal of adding:<br>
<div class="im"><br>
def __setitem__(self,key,value):<br>
self.__dict__[key] = value<br>
</div> dict.__setitem__(self, key, value)<br>
<br>
does not help me.<br>
<br>
What I have today is a class that works like SlowStorage. I want to<br>
replace it with NewStorage because it is 10x faster. That is the only<br>
reason. NewStorage does everything I want and all the APIs work like<br>
SlowStorage except casting to dict.<br>
<br>
By defining __setitem__ as you propose, you solve the casting to dict<br>
issue but you have two unwanted effects: each key,value is store twice<br>
(in different places), accessing the elements becomes slower the<br>
SlowStprage which is my problem in the first place.<br>
<br>
The issue for me is understanding how the casting dict(obj) works and<br>
how to change its behavior so that is uses methods exposed by obj to<br>
do the casting, if all possible.<br></blockquote><div><br></div><div>Then you have two options:</div><div>1) subclass object instead of dict - you're not using any of the features of the dict superclass and the fact that it is a superclass is confusing the dict() constructor.</div>
<div>2) use a different "cast" e.g. d = dict(a.items())</div><div><br></div><div>Oscar</div></div>