summaryrefslogtreecommitdiffstats
path: root/Demo/classes/Dbm.py
diff options
context:
space:
mode:
Diffstat (limited to 'Demo/classes/Dbm.py')
-rwxr-xr-xDemo/classes/Dbm.py90
1 files changed, 45 insertions, 45 deletions
diff --git a/Demo/classes/Dbm.py b/Demo/classes/Dbm.py
index 8d7fe0f..5566f99 100755
--- a/Demo/classes/Dbm.py
+++ b/Demo/classes/Dbm.py
@@ -6,61 +6,61 @@
class Dbm:
- def __init__(self, filename, mode, perm):
- import dbm
- self.db = dbm.open(filename, mode, perm)
+ def __init__(self, filename, mode, perm):
+ import dbm
+ self.db = dbm.open(filename, mode, perm)
- def __repr__(self):
- s = ''
- for key in self.keys():
- t = `key` + ': ' + `self[key]`
- if s: t = ', ' + t
- s = s + t
- return '{' + s + '}'
+ def __repr__(self):
+ s = ''
+ for key in self.keys():
+ t = `key` + ': ' + `self[key]`
+ if s: t = ', ' + t
+ s = s + t
+ return '{' + s + '}'
- def __len__(self):
- return len(self.db)
+ def __len__(self):
+ return len(self.db)
- def __getitem__(self, key):
- return eval(self.db[`key`])
+ def __getitem__(self, key):
+ return eval(self.db[`key`])
- def __setitem__(self, key, value):
- self.db[`key`] = `value`
+ def __setitem__(self, key, value):
+ self.db[`key`] = `value`
- def __delitem__(self, key):
- del self.db[`key`]
+ def __delitem__(self, key):
+ del self.db[`key`]
- def keys(self):
- res = []
- for key in self.db.keys():
- res.append(eval(key))
- return res
+ def keys(self):
+ res = []
+ for key in self.db.keys():
+ res.append(eval(key))
+ return res
- def has_key(self, key):
- return self.db.has_key(`key`)
+ def has_key(self, key):
+ return self.db.has_key(`key`)
def test():
- d = Dbm('@dbm', 'rw', 0600)
- print d
- while 1:
- try:
- key = input('key: ')
- if d.has_key(key):
- value = d[key]
- print 'currently:', value
- value = input('value: ')
- if value == None:
- del d[key]
- else:
- d[key] = value
- except KeyboardInterrupt:
- print ''
- print d
- except EOFError:
- print '[eof]'
- break
- print d
+ d = Dbm('@dbm', 'rw', 0600)
+ print d
+ while 1:
+ try:
+ key = input('key: ')
+ if d.has_key(key):
+ value = d[key]
+ print 'currently:', value
+ value = input('value: ')
+ if value == None:
+ del d[key]
+ else:
+ d[key] = value
+ except KeyboardInterrupt:
+ print ''
+ print d
+ except EOFError:
+ print '[eof]'
+ break
+ print d
test()