On this page
dbm.open
Up: dbm | Next: dbm.whichdb
Rel: dbm.whichdb
Ref: docs.python.org — dbm.open
Tags: #public #python3 #stdlib #dbm
Import
import dbm
from dbm import open
Signature & Overview
dbm.open(file, flag='r', mode=438)
Open or create database at path given by file.
Usage
import dbm
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
path = str(Path(tmp) / "kv")
with dbm.open(path, "c") as db:
db["k"] = "v"
assert db["k"] == b"v"
Gotchas
- Values always come back as
bytes: Even if you assign astr, reading returnsbytes. - No multi-process write locking: Use
sqlite3when concurrent writers exist.
REPL Inspect
from dbm import open
help(open)
Linked from
Related notes
- tuts/python3/stdlib_module/dbm/whichdb Linked here; links to this page; shared tags: #dbm, #stdlib
- tuts/python3/stdlib_module/dbm Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib
- tuts/c/stdlib/ctype/isspace shared tags: #stdlib