当我尝试使用pickle加载dict(具有作为对象数组的对象)时,我得到了palabra对象的属性错误(AttributeError:无法获得属性' palabra' on main& #39;来自C:......)我很困惑如何解决它
加载它:
dict = defaultdict(list)
with open('diccionario.pickle', 'rb') as handle:
d = pickle.load(handle)
dict = d;
class palabra:
def __init__(self,pal,cant):
self.name = pal
self.prob = 0.0
self.cant = cant
并保存
with open('diccionario.pickle', 'wb') as handle:
pickle.dump(dict, handle, protocol=pickle.HIGHEST_PROTOCOL)
我愿意使用csv而不是pickle保存它,但我不知道如何