OrderedDict的jsonpickle子类无法正常工作

时间:2016-12-25 11:40:12

标签: python-3.4 pickle jsonpickle

我做错了什么:

class A(collections.OrderedDict):
    def __init__(self,*largs,**kwargs):
        super(A,self).__init__(*largs,**kwargs);
    def __reduce__(self):
        return super(A,self).__reduce__()

dt = collections.OrderedDict([(1,3),(34,2)]) # pickles fine
d=A([(1,3),(34,2)])                          # pickles fine

js=pickle.dumps([d,dt])
print(js)
temp = pickle.loads(js)
print(temp)

# but it does not jsonpickle.decode ????
js=jsonpickle.encode(d)
print(js)
temp = jsonpickle.decode(js)
print(temp)

1 个答案:

答案 0 :(得分:0)

很明显,我应该为我的课程注册一个特殊的处理程序:

SourceControl.CheckoutItem

然后它起作用