Create database and store key value pairs

import anydbm
db ='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


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 package
dbm in anaconda package

No comments: