annotate Lib/shelve.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 04c28274c281
children b1e6c3fe5de8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
1 """Manage shelves of pickled objects.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
2
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
3 A "shelf" is a persistent, dictionary-like object. The difference
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
4 with dbm databases is that the values (not the keys!) in a shelf can
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
5 be essentially arbitrary Python objects -- anything that the "pickle"
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
6 module can handle. This includes most class instances, recursive data
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
7 types, and objects containing lots of shared sub-objects. The keys
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
8 are ordinary strings.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
9
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
10 To summarize the interface (key is a string, data is an arbitrary
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
11 object):
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
12
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
13 import shelve
2356
6a94119844eb minute comment changes
Guido van Rossum <guido@python.org>
parents: 2303
diff changeset
14 d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
15
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
16 d[key] = data # store data at key (overwrites old data if
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
17 # using an existing key)
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
18 data = d[key] # retrieve data at key (raise KeyError if no
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
19 # such key)
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
20 del d[key] # delete data stored at key (raises KeyError
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
21 # if no such key)
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
22 flag = d.has_key(key) # true if the key exists
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
23 list = d.keys() # a list of all existing keys (slow!)
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
24
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
25 d.close() # close it
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
26
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
27 Dependent on the implementation, closing a persistent dictionary may
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
28 or may not be necessary to flush changes to disk.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
29 """
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
31 # Try using cPickle and cStringIO if available.
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
32
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
33 try:
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
34 from cPickle import Pickler, Unpickler
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
35 except ImportError:
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
36 from pickle import Pickler, Unpickler
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
37
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
38 try:
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
39 from cStringIO import StringIO
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
40 except ImportError:
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
41 from StringIO import StringIO
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
43
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 class Shelf:
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
45 """Base class for shelf implementations.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
46
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
47 This is initialized with a dictionary-like object.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
48 See the module's __doc__ string for an overview of the interface.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
49 """
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 def __init__(self, dict):
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 self.dict = dict
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 def keys(self):
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 return self.dict.keys()
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 def __len__(self):
4263
7b54a3cedbe0 Fix bogus len() call
Guido van Rossum <guido@python.org>
parents: 2967
diff changeset
58 return len(self.dict)
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 def has_key(self, key):
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 return self.dict.has_key(key)
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 def __getitem__(self, key):
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
64 f = StringIO(self.dict[key])
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
65 return Unpickler(f).load()
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 def __setitem__(self, key, value):
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
68 f = StringIO()
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
69 p = Pickler(f)
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 p.dump(value)
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 self.dict[key] = f.getvalue()
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 def __delitem__(self, key):
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 del self.dict[key]
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 def close(self):
2439
c1d27043c22f fix stupid bug (db should be dict)
Guido van Rossum <guido@python.org>
parents: 2356
diff changeset
77 if hasattr(self.dict, 'close'):
c1d27043c22f fix stupid bug (db should be dict)
Guido van Rossum <guido@python.org>
parents: 2356
diff changeset
78 self.dict.close()
c1d27043c22f fix stupid bug (db should be dict)
Guido van Rossum <guido@python.org>
parents: 2356
diff changeset
79 self.dict = None
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
81 def __del__(self):
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
82 self.close()
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
83
5211
314d0d603f06 Added a 'sync' method to shelve. If the underlying database does not have a sync
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4263
diff changeset
84 def sync(self):
314d0d603f06 Added a 'sync' method to shelve. If the underlying database does not have a sync
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4263
diff changeset
85 if hasattr(self.dict, 'sync'):
314d0d603f06 Added a 'sync' method to shelve. If the underlying database does not have a sync
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4263
diff changeset
86 self.dict.sync()
314d0d603f06 Added a 'sync' method to shelve. If the underlying database does not have a sync
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4263
diff changeset
87
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
88
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
89 class BsdDbShelf(Shelf):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
90 """Shelf implementation using the "BSD" db interface.
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
91
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
92 This adds methods first(), next(), previous(), last() and
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
93 set_location() that have no counterpart in [g]dbm databases.
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
94
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
95 The actual database must be opened using one of the "bsddb"
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
96 modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
97 bsddb.rnopen) and passed to the constructor.
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
98
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
99 See the module's __doc__ string for an overview of the interface.
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
100 """
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
101
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
102 def __init__(self, dict):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
103 Shelf.__init__(self, dict)
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
104
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
105 def set_location(self, key):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
106 (key, value) = self.dict.set_location(key)
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
107 f = StringIO(value)
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
108 return (key, Unpickler(f).load())
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
109
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
110 def next(self):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
111 (key, value) = self.dict.next()
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
112 f = StringIO(value)
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
113 return (key, Unpickler(f).load())
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
114
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
115 def previous(self):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
116 (key, value) = self.dict.previous()
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
117 f = StringIO(value)
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
118 return (key, Unpickler(f).load())
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
119
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
120 def first(self):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
121 (key, value) = self.dict.first()
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
122 f = StringIO(value)
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
123 return (key, Unpickler(f).load())
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
124
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
125 def last(self):
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
126 (key, value) = self.dict.last()
5728
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
127 f = StringIO(value)
04c28274c281 Use cPickle and cStringIO when available.
Guido van Rossum <guido@python.org>
parents: 5211
diff changeset
128 return (key, Unpickler(f).load())
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
129
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
130
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
131 class DbfilenameShelf(Shelf):
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
132 """Shelf implementation using the "anydbm" generic dbm interface.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
133
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
134 This is initialized with the filename for the dbm database.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
135 See the module's __doc__ string for an overview of the interface.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
136 """
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
138 def __init__(self, filename, flag='c'):
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 import anydbm
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
140 Shelf.__init__(self, anydbm.open(filename, flag))
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
141
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
142
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
143 def open(filename, flag='c'):
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
144 """Open a persistent dictionary for reading and writing.
2100
4574ed657cc9 shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
2303
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
146 Argument is the filename for the dbm database.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
147 See the module's __doc__ string for an overview of the interface.
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
148 """
505fc478ff08 added __doc__ strings etc.
Guido van Rossum <guido@python.org>
parents: 2100
diff changeset
149
2967
74953a41607c renamed DbShelf->DbfilenameShelf;added BsdDbShelf (David Ely)
Guido van Rossum <guido@python.org>
parents: 2439
diff changeset
150 return DbfilenameShelf(filename, flag)