我有一个简单的类来存储与这样的电路板关联的数据:
class boardClass():
def __init__(self,boardName):
self.__name=boardName
self.__boardMappings= {boardName:{
'FastMode':
{'CPU_A':{'mipi':[], 'gpen':[]},
'CPU_B':{'mipi':[], 'gpen':[]}
'SlowMode':
{'CPU_A':{'mipi':[], 'gpen':[]},
'CPU_B':{'mipi':[], 'gpen':[]}
}
}
}
def setMode(self, board, mode, cpu,mipi,gpen):
self.__boardMappings[board][mode][cpu]['mipi']=mipi
self.__boardMappings[board][mode][cpu]['gpen']=gpen
def getName(self):
return self.__name
我在另一个类中使用 pickle 将boardClass
数据存储在文件中,然后读取它们:
def onSave(self,boardName):
board=boardClass.boardClass(boardName)
name=boardName+".brd"
file=open(name,"wb")
pickle.dump(board,file)
loadedBoard= pickle.load( open( file, "rb" ))
print "Loaded board name is : ",loadedBoard.getName()
当我调用onSave()
方法来腌制 boardClass 时,它会给出几个以这个结尾的错误:
File "C:\Python27\lib\copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle PySwigObject objects
这个 boardClass 是一个非常简单的容器。为什么不能腌制?