Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107470
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> |
| Newsgroups | comp.lang.python |
| Subject | Re: A pickle problem! |
| Date | Fri, 22 Apr 2016 02:52:27 +0100 |
| Organization | Aioe.org NNTP Server |
| Lines | 44 |
| Message-ID | <nfc04n$u2o$1@gioia.aioe.org> (permalink) |
| References | <nfbhh6$dbd$1@gioia.aioe.org> |
| NNTP-Posting-Host | rpgRlhg9tMo1Vs7b/IQ9OA.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.python:107470 |
Show key headers only | View raw
Às 22:43 de 21-04-2016, Paulo da Silva escreveu:
> Hi.
>
> Why in this code fragment self.__name is not kept between pickle
> dumps/loads? How to fix it?
>
> Thanks.
>
> import pickle
> import pandas as pd
> import numpy as np
>
> class C(pd.DataFrame):
> def __init__(self,name,*a,**b):
> super(C,self).__init__(*a,**b)
> self.__name=name
>
> def GetName(self):
> return self.__name
>
# Adding this works but looks tricky!
def __getstate__(self):
dfstate=super(C,self).__getstate__()
cstate=(dfstate,self.__name)
return cstate
def __setstate__(self,cstate):
super(C,self).__setstate__(cstate[0])
self.__name=cstate[1]
>
> dates = pd.date_range('20130101', periods=6)
> c = C("FOO",np.random.randn(6,4), index=dates, columns=list('ABCD'))
>
> cd=pickle.dumps(c,pickle.HIGHEST_PROTOCOL)
>
> d=pickle.loads(cd)
>
> d.GetName()
>
> # AttributeError: 'C' object has no attribute '_C__name'
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A pickle problem! Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2016-04-21 22:43 +0100
Re: A pickle problem! Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2016-04-22 02:52 +0100
Re: A pickle problem! Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-22 10:27 -0600
Re: A pickle problem! Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2016-04-22 21:21 +0100
Re: A pickle problem! Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-22 14:33 -0600
Re: A pickle problem! Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2016-04-22 21:48 +0100
Re: A pickle problem! Fabien <fabien.maussion@gmail.com> - 2016-04-24 12:20 +0200
csiph-web