【问题标题】:Python DBM Module for Windows?适用于 Windows 的 Python DBM 模块?
【发布时间】:2011-03-25 09:49:55
【问题描述】:

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

有没有人知道具有相似语法的类似模块或解决方法以在 Windows 上获得 dmb 功能?能够访问写入硬盘驱动器的数据库就像我编写访问字典的方式一样很棒。感谢您的帮助!

【问题讨论】:

标签: python database module dbm


【解决方案1】:

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

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

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

【讨论】:

【解决方案2】:

根据使用 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'

【讨论】:

  • 这个答案已经过时了。 dbhash 在 Python 3 中被删除。
【解决方案3】:

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

“dumbdbm 模块旨在作为最后的备用方案 没有更强大的模块可用时的 anydbm 模块。笨蛋 模块不是为速度而编写的,也没有像 其他数据库模块。”

【讨论】:

    【解决方案4】:

    如果 Python 3 具有相关性,我会选择外部 k-v 解决方案,因为 dumbdbm 并不快乐。

    一些纯 Python 选项:

    • semidbm - 一种比dumbdbm 更快的替代方案,仅限Python 标准库,pip and go。如果我想确保对用户的可移植性和可用性,我会选择这个。

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

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

    还有LMDBUnQLiteSQLite4 LSM 的 Python 包装器,所有这些都支持 Windows,但未测试 SQLite4 绑定。

    后两位作者是 Charles Leifer,他既熟悉 k-v stores 又是狂热的 Python 开发人员(请参阅 Peewee)。

    就LMDB而言,我已经尝试了一段时间。没有抱怨,但它使用事务模型,您不能像使用其他 dbm 那样使用字典样式,除非您子类化/撰写/提交拉取请求等。 此外,它明确地doesn't utilize compression(见also)是我感兴趣的。

    所以 LMDB 不太适合我的特定需求。它似乎功能强大,绑定运行良好,安装它们也很容易(pip 对我有用,不需要单独安装 LMDB 或任何麻烦)。

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多