回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我从macports运行python3.1.4,并尝试在这里使用shelve模块。我可以在另一台开发机器(不同的操作系统等)上成功地使用它,所以我不确定我可能做的不正确。。。在</p>
<p>如有任何想法或建议,我们将不胜感激!在</p>
<p>这是错误
"数据库错误:无法确定数据库类型“
(我搜索了错误消息,但没有找到任何信息-我甚至试图强制protocl=2看看这是否有用,但没有用)</p>
<p>以下是互动环节:</p>
<pre><code>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
</code></pre>