[Python-checkins] r50904 - python/trunk/Doc/lib/libshelve.tex
andrew.kuchling
python-checkins at python.org
Fri Jul 28 14:45:55 CEST 2006
Author: andrew.kuchling
Date: Fri Jul 28 14:45:55 2006
New Revision: 50904
Modified:
python/trunk/Doc/lib/libshelve.tex
Log:
Don't overwrite built-in name; add some blank lines for readability
Modified: python/trunk/Doc/lib/libshelve.tex
==============================================================================
--- python/trunk/Doc/lib/libshelve.tex (original)
+++ python/trunk/Doc/lib/libshelve.tex Fri Jul 28 14:45:55 2006
@@ -143,15 +143,17 @@
del d[key] # delete data stored at key (raises KeyError
# if no such key)
flag = d.has_key(key) # true if the key exists
-list = d.keys() # a list of all existing keys (slow!)
+klist = d.keys() # a list of all existing keys (slow!)
# as d was opened WITHOUT writeback=True, beware:
d['xx'] = range(4) # this works as expected, but...
d['xx'].append(5) # *this doesn't!* -- d['xx'] is STILL range(4)!!!
+
# 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
+
# 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.
More information about the Python-checkins
mailing list