From 8b01fc8531eab109b4915672842204d760120654 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Wed, 20 Aug 2025 22:47:31 +0300 Subject: [PATCH] Add examples of explicit DBM backend selection in shelve module --- Doc/library/shelve.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Doc/library/shelve.rst b/Doc/library/shelve.rst index b88fe4157bdc29..299cfb6e6e86da 100644 --- a/Doc/library/shelve.rst +++ b/Doc/library/shelve.rst @@ -262,6 +262,23 @@ object):: d.close() # close it +The :func:`shelve.open` function automatically selects an available DBM backend +implementation. You can explicitly select the DBM backend by using +:class:`shelve.Shelf` with a specific backend: + +.. code-block:: python + + import shelve + import dbm + + # Use SQLite3 as DBM backend + with shelve.Shelf(dbm.sqlite3.open("data.shelf", "c")) as shelf: + shelf["int"] = 4 + + # Use GNU DBM as backend + with shelve.Shelf(dbm.gnu.open("data.gnu", "c")) as shelf: + shelf["foo"] = "bar" + Exceptions ----------