These days, most folks use the anydbm meta-module to interface with db-like databases. But the API is essentially dict-like; see PyMOTW for some examples. Note that bsddb is deprecated in 2.6.1 and will be gone in 3.x. Switching to anydbm will make the upgrade easier; switching to sqlite (which is now in stdlib) will give you a much more flexible store.
发布评论
评论(5)
如今,大多数人使用 anydbm 元模块来与类似 db 的数据库进行交互。 但 API 本质上是类似字典的; 请参阅 PyMOTW 了解一些示例。 请注意,bsddb 在 2.6.1 中已弃用,并将在 3.x 中消失。 切换到anydbm将使升级变得更加容易; 切换到 sqlite(现在位于 stdlib 中)将为您提供更灵活的存储。
These days, most folks use the anydbm meta-module to interface with db-like databases. But the API is essentially dict-like; see PyMOTW for some examples. Note that bsddb is deprecated in 2.6.1 and will be gone in 3.x. Switching to anydbm will make the upgrade easier; switching to sqlite (which is now in stdlib) will give you a much more flexible store.
从 http://pypi.python.org/pypi 下载源代码后查看:Lib3/bsddb/test /bsddb3/
当前发行版包含以下测试,对于开始使用 bsddb3 非常有帮助:
Look at: Lib3/bsddb/test after downloading the source from http://pypi.python.org/pypi/bsddb3/
The current distribution contains the following tests that are very helpful to start working with bsddb3:
我假设该线程仍然处于活动状态,所以我们开始吧。 这是粗略的代码,没有错误检查,但作为起点可能很有用。
我想使用 PHP 的内置 DBA 函数,然后使用 Python (2.x) 脚本读取数据库。 这是创建数据库的 PHP 脚本:
现在,这是插入条目的 PHP 代码: 我使用 JSON 来保存“真实”数据:
现在,这是您和我真正感兴趣的代码,它使用 Python 的 bsddb3模块。
I'm assuming this thread is still active, so here we go. This is rough code and there's no error checking, but it may be useful as a starting point.
I wanted to use PHP's built-in DBA functions and then read the database using a Python (2.x) script. Here's the PHP script that creates the database:
Now, here's the PHP code to insert an entry: I use JSON to hold the "real" data:
Now, here's the code that you and I are actually interested in, and it uses Python's bsddb3 module.
搜索“import bsddb”,我得到:
...但我个人强烈建议您使用 sqlite 而不是 bsddb,人们正在使用前者更多是有原因的。
Searching for "import bsddb", I get:
...but personally I'd heavily recommend you use sqlite instead of bsddb, people are using the former a lot more for a reason.
Gramps 谱系程序使用 bsddb 作为其数据库
The Gramps genealogy program uses bsddb for its database