mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
#17040: document that shelve.open() and the Shelf object can be used as context managers. Initial patch by Berker Peksag.
This commit is contained in:
parent
894499fa27
commit
d23c0a8992
1 changed files with 12 additions and 4 deletions
|
|
@ -44,8 +44,11 @@ lots of shared sub-objects. The keys are ordinary strings.
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Do not rely on the shelf being closed automatically; always call
|
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
|
:meth:`~Shelf.close` explicitly when you don't need it any more, or
|
||||||
:keyword:`with` statement with :func:`contextlib.closing`.
|
use :func:`shelve.open` as a context manager::
|
||||||
|
|
||||||
|
with shelve.open('spam') as db:
|
||||||
|
db['eggs'] = 'eggs'
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
|
@ -118,10 +121,15 @@ Restrictions
|
||||||
The *keyencoding* parameter is the encoding used to encode keys before they
|
The *keyencoding* parameter is the encoding used to encode keys before they
|
||||||
are used with the underlying dict.
|
are used with the underlying dict.
|
||||||
|
|
||||||
.. versionadded:: 3.2
|
:class:`Shelf` objects can also be used as context managers.
|
||||||
The *keyencoding* parameter; previously, keys were always encoded in
|
|
||||||
|
.. versionchanged:: 3.2
|
||||||
|
Added the *keyencoding* parameter; previously, keys were always encoded in
|
||||||
UTF-8.
|
UTF-8.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.4
|
||||||
|
Added context manager support.
|
||||||
|
|
||||||
|
|
||||||
.. class:: BsdDbShelf(dict, protocol=None, writeback=False, keyencoding='utf-8')
|
.. class:: BsdDbShelf(dict, protocol=None, writeback=False, keyencoding='utf-8')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue