1 # A wrapper around the (optional) built-in class dbm, supporting keys
2 # and values of almost any type instead of just string.
3 # (Actually, this works only for keys and values that can be read back
4 # correctly after being converted to a string.)
9 def __init__(self
, filename
, mode
, perm
):
11 self
.db
= dbm
.open(filename
, mode
, perm
)
15 for key
in self
.keys():
16 t
= repr(key
) + ': ' + repr(self
[key
])
24 def __getitem__(self
, key
):
25 return eval(self
.db
[repr(key
)])
27 def __setitem__(self
, key
, value
):
28 self
.db
[repr(key
)] = repr(value
)
30 def __delitem__(self
, key
):
31 del self
.db
[repr(key
)]
35 for key
in self
.db
.keys():
39 def has_key(self
, key
):
40 return self
.db
.has_key(repr(key
))
44 d
= Dbm('@dbm', 'rw', 0600)
51 print 'currently:', value
52 value
= input('value: ')
57 except KeyboardInterrupt: