Skip to content

Commit 8b01fc8

Browse files
committed
Add examples of explicit DBM backend selection in shelve module
1 parent 7dc42b6 commit 8b01fc8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Doc/library/shelve.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,23 @@ object)::
262262

263263
d.close() # close it
264264

265+
The :func:`shelve.open` function automatically selects an available DBM backend
266+
implementation. You can explicitly select the DBM backend by using
267+
:class:`shelve.Shelf` with a specific backend:
268+
269+
.. code-block:: python
270+
271+
import shelve
272+
import dbm
273+
274+
# Use SQLite3 as DBM backend
275+
with shelve.Shelf(dbm.sqlite3.open("data.shelf", "c")) as shelf:
276+
shelf["int"] = 4
277+
278+
# Use GNU DBM as backend
279+
with shelve.Shelf(dbm.gnu.open("data.gnu", "c")) as shelf:
280+
shelf["foo"] = "bar"
281+
265282
266283
Exceptions
267284
----------

0 commit comments

Comments
 (0)