用于dill
序列化类时:
import dill, pickle
class project(object):
def __init__(self, name='', folder='', user_id='', version=-1 ):
self.name, self.folder, self.user_id, self.version = name, folder, user_id, version
# Other code, not shown, since Big class .......
dill.dump(proj1, open('test_dill.pkl', 'w'), byref=False )
我收到这条消息:
PicklingError: Can't pickle <built-in function raw_input>: it's not the same object as __builtin__.raw_input
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 236, in dump
pik.dump(obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 224, in dump
self.save(obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 401, in save_reduce
save(args)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 554, in save_tuple
save(element)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 401, in save_reduce
save(args)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 554, in save_tuple
save(element)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 401, in save_reduce
save(args)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 554, in save_tuple
save(element)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 401, in save_reduce
save(args)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 554, in save_tuple
save(element)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 606, in save_list
self._batch_appends(iter(obj))
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 642, in _batch_appends
save(tmp[0])
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 425, in save_reduce
save(state)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "D:\_devs\Python01\Anaconda27\lib\site-packages\dill\dill.py", line 993, in save_builtin_method
StockPickler.save_global(pickler, obj)
File "D:\_devs\Python01\Anaconda27\lib\pickle.py", line 759, in save_global
(obj, module, name))
PicklingError: Can't pickle <built-in function raw_input>: it's not the same object as __builtin__.raw_input
我不确定是否可以通过代码修改内置函数......
这听起来很神秘。