summaryrefslogtreecommitdiff
path: root/Doc/library/shelve.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/shelve.rst')
-rw-r--r--Doc/library/shelve.rst17
1 files changed, 13 insertions, 4 deletions
diff --git a/Doc/library/shelve.rst b/Doc/library/shelve.rst
index 048f80afa0..22e202dace 100644
--- a/Doc/library/shelve.rst
+++ b/Doc/library/shelve.rst
@@ -44,8 +44,11 @@ lots of shared sub-objects. The keys are ordinary strings.
.. note::
Do not rely on the shelf being closed automatically; always call
- :meth:`close` explicitly when you don't need it any more, or use a
- :keyword:`with` statement with :func:`contextlib.closing`.
+ :meth:`~Shelf.close` explicitly when you don't need it any more, or
+ use :func:`shelve.open` as a context manager::
+
+ with shelve.open('spam') as db:
+ db['eggs'] = 'eggs'
.. warning::
@@ -118,10 +121,16 @@ Restrictions
The *keyencoding* parameter is the encoding used to encode keys before they
are used with the underlying dict.
- .. versionadded:: 3.2
- The *keyencoding* parameter; previously, keys were always encoded in
+ A :class:`Shelf` object can also be used as a context manager, in which
+ case it will be automatically closed when the :keyword:`with` block ends.
+
+ .. versionchanged:: 3.2
+ Added the *keyencoding* parameter; previously, keys were always encoded in
UTF-8.
+ .. versionchanged:: 3.4
+ Added context manager support.
+
.. class:: BsdDbShelf(dict, protocol=None, writeback=False, keyencoding='utf-8')