【发布时间】:2014-04-08 20:04:41
【问题描述】:
如何使用 Python 读取 Berkeley DB 文件?
我有这个文件...
[root@dhcp-idev1 ndb]# file dhcp.ndb
dhcp.ndb: Berkeley DB (Btree, version 9, native byte-order)
...所以我想我可以做到...
[root@dhcp-idev1 ndb]# python2.3
Python 2.3.4 (#1, Jul 16 2009, 07:01:37)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import anydbm
>>> anydbm.open( './dhcp.ndb' )
...但我收到此错误消息...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/anydbm.py", line 80, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined
>>>
...我做错了什么?
【问题讨论】:
-
您是否尝试过直接使用
dbm.open、gdbm.open或dbhash.open?此外,dbm后端在给定文件名中添加了.db扩展名,因此请尝试将文件重命名为dhcp.db并使用dbm.open('dhcp')打开它。
标签: python berkeley-db