shelve无法打开刚刚创建的文件

时间:2015-07-19 03:14:14

标签: python python-2.5

使用python25我有搁置的问题。我尝试了一个非常基本的例子:

>>> info_file = shelve.open('test')
>>> info_file['test'] ='hello'
>>> info_file.close()

>>> info_file = shelve.open('test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.pyenv/versions/2.5/lib/python2.5/shelve.py", line 225, in open
    return DbfilenameShelf(filename, flag, protocol, writeback)
  File "~/.pyenv/versions/2.5/lib/python2.5/shelve.py", line 209, in __init__
    Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
  File "~/.pyenv/versions/2.5/lib/python2.5/anydbm.py", line 80, in open
    raise error, "db type could not be determined"
anydbm.error: db type could not be determined

它适用于Debian环境。但不是我的MACOSX

我在这里读到:

http://www.gossamer-threads.com/lists/python/python/13922

可能是因为我没有DB处理程序,但是如何安装数据库处理程序(可能带有pip)以及我应该安装哪个数据库处理程序

1 个答案:

答案 0 :(得分:0)

此错误的解决方案是:

import anydbm
anydbm._defaultmod = __import__('dumbdbm')