我从macports运行python3.1.4,并尝试在这里使用shelve模块。我可以在另一台开发机器(不同的操作系统等)上成功地使用它,所以我不确定我可能做的不正确。。。在
如有任何想法或建议,我们将不胜感激!在
这是错误 "数据库错误:无法确定数据库类型“ (我搜索了错误消息,但没有找到任何信息-我甚至试图强制protocl=2看看这是否有用,但没有用)
以下是互动环节:
Python 3.1.4 (default, Oct 7 2011, 15:58:53)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>>> import shelve
>>> a = [1, 2, 3]
>>> locker = shelve.open('myshelf',protocol=2)
>>> locker['a'] = a
>>> locker.close()
>>> exit()
Python 3.1.4 (default, Oct 7 2011, 15:58:53)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>>> import shelve
>>> locker = shelve.open('myshelf',protocol=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shelve.py", line 231, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shelve.py", line 215, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/dbm/__init__.py", line 84, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined
这看起来像是MacPorts端口或python3中的bug。对我来说,您的示例可以在当前的MacPortsPython2.7.2上使用,但在当前的MacPortsPython3.2.2中失败的方式与您报告的相同。MacPorts自动构建并包含}。看起来MacPorts2.7.2使用的是db46并且可以工作,但是3.2.2使用
gdbm
作为python3端口的数据库管理器;对于python2,它同时包含BerkeleyDB4.6
和{gdbm
失败;大概MacPorts3.1端口是类似的。这应该进一步调查。在更新:如果您使用的是最新的MacPorts安装,这很可能是http://bugs.python.org/issue13007中报告的问题。看起来有一个修复程序可以支持最新的
gdbm 1.9
及更高版本—当前的MacPorts版本是1.9.1。这个修复是在python3.2.2发布后应用的(它将在3.2.3中);MacPorts人员应该将其反向移植到Python端口。在使用MacPorts或Homebrew安装ndbm。用它来创建数据库。稍后打开文件时,shelve将调用数据库管理并将成功识别该文件。在
相关问题 更多 >
编程相关推荐