summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-10-30 12:38:16 (GMT)
committerGuido van Rossum <guido@python.org>1993-10-30 12:38:16 (GMT)
commitbecec31f170e656bc49163f7a50b30238218876a (patch)
treef464e79d10d9973ba714bad290847ff63a7108a9 /Demo
parent74b3f8a9e3368ad10a8d4aebd2dbaffdd3ca3585 (diff)
downloadcpython-becec31f170e656bc49163f7a50b30238218876a.zip
cpython-becec31f170e656bc49163f7a50b30238218876a.tar.gz
cpython-becec31f170e656bc49163f7a50b30238218876a.tar.bz2
Fix bug and use __init__
Diffstat (limited to 'Demo')
-rwxr-xr-xDemo/classes/Dbm.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/Demo/classes/Dbm.py b/Demo/classes/Dbm.py
index 8fccb6a..0bd5491 100755
--- a/Demo/classes/Dbm.py
+++ b/Demo/classes/Dbm.py
@@ -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: