Let me rephrase the first sentence of my last post: I don&#39;t think the issue is inheritance of just *any* class, but specifically inheritance of built-in types. :)<br><br>- Atul<br><br><div class="gmail_quote">On Sun, May 18, 2008 at 12:06 PM, Atul Varma &lt;<a href="mailto:varmaa@gmail.com">varmaa@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I could be wrong, but I don&#39;t think the issue is inheritance--I think it&#39;s actually because you&#39;re subclassing a built-in type, which requires doing some special stuff with pickle (namely, registering with copy_reg as you&#39;ve done in your last email).<br>

<br>If you use pickle instead of cPickle, you get a more informative traceback; take a look at pickle.Pickler and notice how the dispatch table, which appears to map types to serialization functions, maps the dictionary type to Pickler.save_dict().&nbsp; I think that has something to do with it.<br>

<br>Hope that helps...&nbsp; I have to run so I can&#39;t look into this more right now, but let me know if you&#39;d like me to.<br><font color="#888888"><br>- Atul</font><div><div></div><div class="Wj3C7c"><br><br>On Sun, May 18, 2008 at 11:58 AM, Massimo Di Pierro &lt;<a href="mailto:mdipierro@cs.depaul.edu" target="_blank">mdipierro@cs.depaul.edu</a>&gt; wrote:<br>

<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Odd... this works instead...<br>
<br>
from cPickle import *<br>
import copy_reg<br>
<br>
class S(dict):<br>
 &nbsp; &nbsp;def __getattr__(self,key): return self[key]<div><br>
 &nbsp; &nbsp;def __setattr__(self, key, value): self[key]=value<br>
<br>
class A(S):<br>
 &nbsp; &nbsp;def __init__(self): self.i=lambda u: u<br>
 &nbsp; &nbsp;#def __getstate__(self): return {}<br>
<br></div>
def unserialize_A(d):<br>
 &nbsp; &nbsp;return A()<br>
<br>
def serialize_A(o):<br>
 &nbsp; &nbsp;return unserialize_A, ({},)<br>
<br>
copy_reg.pickle(A, serialize_A)<br>
<br>
a=A()<br>
print a.i(3)<br>
x=dumps(a)<br>
b=loads(x)<br>
print b.i(4)<br>
<br>
I guess the rule is use copy_reg and not __getstate__ if you have inheritance.<div><div></div><div><br>
<br>
<br>
On May 18, 2008, at 1:44 PM, Massimo Di Pierro wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
does anybody know why the following code does not work?<br>
<br>
 &nbsp; &nbsp; from cPickle import *<br>
<br>
 &nbsp; &nbsp; class S(dict):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; def __setattr__(self, key, value): self[key]=value<br>
 &nbsp; &nbsp; class A(S):<br>
 &nbsp; &nbsp; &nbsp; &nbsp;def __init__(self): self.i=lambda u: u<br>
 &nbsp; &nbsp; &nbsp; &nbsp;def __getstate__(self): return {}<br>
<br>
 &nbsp; &nbsp; a=A()<br>
 &nbsp; &nbsp; x=dumps(a)<br>
<br>
I know that self.i is a lambda and thus not pickable but __getstate__<br>
is called (I checked) and thus it should not matter. I guess I do not<br>
undretansd how pickling under inheritance.<br>
<br>
Massimo<br>
_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
</blockquote>
<br>
_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>