In [1]:
import dbm
with dbm.open('/tmp/example.db', 'n') as db:
db['key'] = 'value'
db['today'] = 'Sunday'
db['author'] = 'Doug'
In [2]:
import dbm
print(dbm.whichdb('/tmp/example.db'))
In [3]:
import dbm
with dbm.open('/tmp/example.db', 'r') as db:
print('keys():', db.keys())
for k in db.keys():
print('iterating:', k, db[k])
print('db["author"] =', db['author'])
In [4]:
import dbm
with dbm.open('/tmp/example.db', 'w') as db:
try:
db[1] = 'one'
except TypeError as err:
print(err)
In [5]:
import dbm
with dbm.open('/tmp/example.db', 'w') as db:
try:
db['one'] = 1
except TypeError as err:
print(err)