1

我有一个包含 RAM 的大型字典对象dict_tmp40GB系统总共有64GB),它具有字符串键和浮点值。我使用d = shelve.open(fname, protocol=2)andd['dict_tmp'] = dict_tmp来保存字典,这会产生 foll 错误:

Traceback (most recent call last):
  File "file.py", line 160, in <module>
    d['dict_tmp'] = dict_tmp
  File "/usr/lib/python2.7/shelve.py", line 133, in __setitem__
    self.dict[key] = f.getvalue()
  File "/usr/lib/python2.7/bsddb/__init__.py", line 279, in __setitem__
    _DeadlockWrap(wrapF)  # self.db[key] = value
  File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap
    return function(*_args, **_kwargs)
  File "/usr/lib/python2.7/bsddb/__init__.py", line 278, in wrapF
    self.db[key] = value
TypeError: Data values must be of type string or None.

我相信搁置模块适用于一般的python对象,但我认为这个问题可能与anydbm有关。任何帮助将非常感激!

抛开问题不谈:如果不搁置(如在此处此处回答),那么保存大型词典的最佳方法是什么?太感谢了!

4

0 回答 0