在 macOS 上使用适用于 Python 3.6.3 的 dbm.gnu

Sea*_*ito 5 gnu dbm python-3.x

我正在尝试打开一个.db类型为 的文件db.gnu。尝试使用内置 Python 3 模块打开它dbm失败并显示以下消息:

dbm.error: db type is dbm.gnu, but the module is not available
Run Code Online (Sandbox Code Playgroud)

我知道我必须使用gnu子模块来dbm打开它。但是,我无法在 macOS 上的 Python 3.6.3 中执行此操作:

In [1]: import dbm
In [2]: dbm.gnu
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-ddbd370a1085> in <module>()
----> 1 dbm.gnu

AttributeError: module 'dbm' has no attribute 'gnu'
Run Code Online (Sandbox Code Playgroud)

如何dbm.gnu在 Mac 上使用?

Mit*_*rie 3

我会尝试brew install gdbm

之后我尝试:

Python 3.6.4 (default, Jan  6 2018, 11:51:59)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm.gnu
>>> print(dbm.gnu)
<module 'dbm.gnu' from '/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/dbm/gnu.py'>
>>> import dbm
>>> dbm.gnu
<module 'dbm.gnu' from '/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/dbm/gnu.py'>
Run Code Online (Sandbox Code Playgroud)