Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit becec31

Browse files
committed
Fix bug and use __init__
1 parent 74b3f8a commit becec31

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

Demo/classes/Dbm.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
44
# correctly after being converted to a string.)
55

66

7-
def opendbm(filename, mode, perm):
8-
return Dbm().init(filename, mode, perm)
9-
10-
117
class Dbm:
128

13-
def init(self, filename, mode, perm):
9+
def __init__(self, filename, mode, perm):
1410
import dbm
1511
self.db = dbm.open(filename, mode, perm)
16-
return self
1712

1813
def __repr__(self):
1914
s = ''
2015
for key in self.keys():
2116
t = `key` + ': ' + `self[key]`
22-
if s: t = t + ', '
17+
if s: t = ', ' + t
2318
s = s + t
2419
return '{' + s + '}'
2520

@@ -46,15 +41,15 @@ def has_key(self, key):
4641

4742

4843
def test():
49-
d = opendbm('@dbm', 'rw', 0666)
44+
d = Dbm('@dbm', 'rw', 0666)
5045
print d
5146
while 1:
5247
try:
5348
key = eval(raw_input('key: '))
5449
if d.has_key(key):
5550
value = d[key]
5651
print 'currently:', value
57-
value = eval(raw_input('value: '))
52+
value = input('value: ')
5853
if value == None:
5954
del d[key]
6055
else:

0 commit comments

Comments
 (0)