Create database and store key value pairs

import anydbm
db = anydbm.open('captions.db', 'c')
db['c1'] = 'Photo of John Cleese.'
print db['c1']
db['c2'] = 'Photo of John Cleese doing a silly walk.'
print db['c2']

for key in db:
      print key

db.close()

Value Meaning
'r' Open existing database for reading only (default)
'w' Open existing database for reading and writing
'c' Open database for reading and writing, creating it if it doesn’t exist 
'n' Always create a new, empty database, open for reading and writing

anydbm in python.org package
dbm in anaconda package

No comments: