适用于 Windows 的 Python DBM 模块?

发布于 2024-09-13 01:53:55 字数 250 浏览 1 评论 0 原文

我想在我的 Windows 机器上使用 dbm 模块,但目前仅在 Unix 上支持。 http://docs.python.org/library/dbm.html

有谁知道具有类似语法的类似模块或使 dmb 在 Windows 上运行的解决方法?能够访问写入硬盘的数据库就像我编码访问字典的方式一样,那就太好了。感谢您的帮助!

I would like to use the dbm module on my Windows machine, but it is currently only supported on Unix. http://docs.python.org/library/dbm.html

Does anyone know of a similar module with similar syntax or a workaround to get dmb functional on windows? Being able to access a database written to the hard drive much like how I code to access a dictionary would be great. Thank you for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ˉ厌 2024-09-20 01:53:55

实际上,经过更多谷歌搜索后,我发现了这个:

http://docs.python。 org/library/anydbm.html#module-anydbm

我已经在 Windows 上尝试过这个,它似乎工作正常 =)

Actually, after more googling around, I found this:

http://docs.python.org/library/anydbm.html#module-anydbm

I've tried this on windows and it seems to be working fine =)

韶华倾负 2024-09-20 01:53:55

如果 Python 3 相关,我会选择外部 kv 解决方案,如 dumbdbm< /a> 一点也不快乐。

一些纯Python选项:

  • semidbm - 更快的dumbdbm替代品,仅限Python标准库,pip然后走吧。如果我想确保用户的可移植性和可用性,我会选择这个。

  • PickleDB - 使用 json 序列化数据。仅 Standrad 库,我没有进行基准测试,但由于序列化开销,我怀疑它比 semidbm 慢。

  • Petite DB - 我自己使用 Python 的 zipfile 模块的简单解决方法。书中的基本测试,但尚未准备好用于生产。

还有 LMDBUnQLiteSQLite4 LSM ,所有这些都支持 Windows,但 SQLite4 绑定尚未测试。

后两篇文章由 Charles Leifer 编写,他精通 kv 存储,并且热衷于 Python开发人员(请参阅 Peewee)。

至于LMDB,我已经尝试了一段时间了。没有抱怨,但它使用事务模型,您不能像其他 dbm 一样使用字典样式,除非您子类化/撰写/提交拉取请求等。
此外,它明确不利用压缩(请参阅)这是我感兴趣的。

所以LMDB只是不太符合我的具体需求。它似乎确实功能强大,绑定工作正常,并且安装它们并不麻烦(pip 对我有用,不需要单独安装 LMDB 或任何麻烦)。

If Python 3 is of relevance, I'd go for an external k-v solution, as dumbdbm is no joy.

Some pure Python options:

  • semidbm - A faster alternative to dumbdbm, Python standard library only, pip and go. The one I'd go for if I want to ensure portability and availability to users.

  • PickleDB - Uses json to serialize data. Standrad library only, I haven't benchmarked but I suspect it's slower than semidbm because of the serialization overhead.

  • Petite DB - My own simple workaround using Python's zipfile module. Basic testing in the books but it's not production ready.

There are also Python wrappers to LMDB, UnQLite and SQLite4 LSM, all of which support Windows, though the SQLite4 bindings weren't tested.

The latter two are by Charles Leifer, who is both savvy with k-v stores and an avid Python developer (see Peewee).

As far as LMDB, I've tried it for a while. No complaints, but it uses a transactional model, where you can't use it dictionary-style like with other dbm's, unless you subclass/compose/submit a pull request etc.
Also, it explicitly doesn't utilize compression (see also) which was something I was interested in.

So LMDB just didn't quite fit my specific needs. It does seem to be highly capable, the bindings worked fine, and installing them was untroublesome (pip worked for me, had no need to install LMDB seperately or any nuisance to that effect).

猫弦 2024-09-20 01:53:55

根据使用 Python 2.7.2 在 Windows 7 系统上进行的以下测试,Windows 安装似乎支持 dbhash。

import os

import anydbm

import whichdb

file = os.curdir + '/testdbm'   # define a test file name in the current directory

d = anydbm.open(file, 'c')      # create a new database using the test file name

db_type = whichdb.whichdb(file) # get the dbm database type

print(db_type)                  # display the result

'dbhash'

Based on the following test on a Windows 7 system using Python 2.7.2 it appears that dbhash is supported on Windows instalations.

import os

import anydbm

import whichdb

file = os.curdir + '/testdbm'   # define a test file name in the current directory

d = anydbm.open(file, 'c')      # create a new database using the test file name

db_type = whichdb.whichdb(file) # get the dbm database type

print(db_type)                  # display the result

'dbhash'
舟遥客 2024-09-20 01:53:55

我认为 Windows 上的anydbm 只会加载dumbdbm,因为所有其他模块似乎仅适用于Unix。根据Python文档...

“dumbdbm 模块旨在作为最后的备用手段
当没有更强大的模块可用时,使用任何dbm 模块。哑巴数据库
模块不是为了速度而编写的,并且几乎没有像
其他数据库模块。”

I think anydbm on Windows will only load dumbdbm, since all the other modules appear to be Unix only. According to the Python documentation...

"The dumbdbm module is intended as a last resort fallback for the
anydbm module when no more robust module is available. The dumbdbm
module is not written for speed and is not nearly as heavily used as
the other database modules."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文