diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-10 09:01:23 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-10 09:01:23 (GMT) |
commit | dba903993a8d3e13d2cf83d6a8912e908025b17b (patch) | |
tree | b0f7d957452d40ce384e5d0a1382067e3379f60f /Doc/library/shelve.rst | |
parent | 387235085c5a6a1d823b0af3fabb42830c88f984 (diff) | |
download | cpython-dba903993a8d3e13d2cf83d6a8912e908025b17b.zip cpython-dba903993a8d3e13d2cf83d6a8912e908025b17b.tar.gz cpython-dba903993a8d3e13d2cf83d6a8912e908025b17b.tar.bz2 |
Issue #23921: Standardized documentation whitespace formatting.
Original patch by James Edwards.
Diffstat (limited to 'Doc/library/shelve.rst')
-rw-r--r-- | Doc/library/shelve.rst | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/Doc/library/shelve.rst b/Doc/library/shelve.rst index 204967a..f89368b 100644 --- a/Doc/library/shelve.rst +++ b/Doc/library/shelve.rst @@ -165,32 +165,33 @@ object):: import shelve - d = shelve.open(filename) # open -- file may get suffix added by low-level - # library - - d[key] = data # store data at key (overwrites old data if - # using an existing key) - data = d[key] # retrieve a COPY of data at key (raise KeyError if no - # such key) - del d[key] # delete data stored at key (raises KeyError - # if no such key) - flag = key in d # true if the key exists - klist = list(d.keys()) # a list of all existing keys (slow!) + d = shelve.open(filename) # open -- file may get suffix added by low-level + # library + + d[key] = data # store data at key (overwrites old data if + # using an existing key) + data = d[key] # retrieve a COPY of data at key (raise KeyError + # if no such key) + del d[key] # delete data stored at key (raises KeyError + # if no such key) + + flag = key in d # true if the key exists + klist = list(d.keys()) # a list of all existing keys (slow!) # as d was opened WITHOUT writeback=True, beware: - d['xx'] = [0, 1, 2] # this works as expected, but... - d['xx'].append(3) # *this doesn't!* -- d['xx'] is STILL [0, 1, 2]! + d['xx'] = [0, 1, 2] # this works as expected, but... + d['xx'].append(3) # *this doesn't!* -- d['xx'] is STILL [0, 1, 2]! # having opened d without writeback=True, you need to code carefully: - temp = d['xx'] # extracts the copy - temp.append(5) # mutates the copy - d['xx'] = temp # stores the copy right back, to persist it + temp = d['xx'] # extracts the copy + temp.append(5) # mutates the copy + d['xx'] = temp # stores the copy right back, to persist it # or, d=shelve.open(filename,writeback=True) would let you just code # d['xx'].append(5) and have it work as expected, BUT it would also # consume more memory and make the d.close() operation slower. - d.close() # close it + d.close() # close it .. seealso:: |