]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix bug and use __init__
authorGuido van Rossum <guido@python.org>
Sat, 30 Oct 1993 12:38:16 +0000 (12:38 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 30 Oct 1993 12:38:16 +0000 (12:38 +0000)
Demo/classes/Dbm.py

index 8fccb6a2f4ad12376514b28b253533e42cdb67a1..0bd5491f6733d0a03513bd23ca3cb0099c58e52e 100755 (executable)
@@ -4,22 +4,17 @@
 # correctly after being converted to a string.)
 
 
-def opendbm(filename, mode, perm):
-       return Dbm().init(filename, mode, perm)
-
-
 class Dbm:
 
-       def init(self, filename, mode, perm):
+       def __init__(self, filename, mode, perm):
                import dbm
                self.db = dbm.open(filename, mode, perm)
-               return self
 
        def __repr__(self):
                s = ''
                for key in self.keys():
                        t = `key` + ': ' + `self[key]`
-                       if s: t = t + ', '
+                       if s: t = ', ' + t
                        s = s + t
                return '{' + s + '}'
 
@@ -46,7 +41,7 @@ class Dbm:
 
 
 def test():
-       d = opendbm('@dbm', 'rw', 0666)
+       d = Dbm('@dbm', 'rw', 0666)
        print d
        while 1:
                try:
@@ -54,7 +49,7 @@ def test():
                        if d.has_key(key):
                                value = d[key]
                                print 'currently:', value
-                       value = eval(raw_input('value: '))
+                       value = input('value: ')
                        if value == None:
                                del d[key]
                        else: