file close(close sometimes required internallyimporting the dbm standard library module automatically loads whatever dbm interface is available in your python interpreter (attempting alternatives in fixed order)and opening the new dbm file creates one or more external files with names that start with the string 'movie(more on the details in momentbut after the import and opena dbm file is virtually indistinguishable from dictionary in effectthe object called file here can be thought of as dictionary mapped to an external file called moviethe only obvious differences are that keys must be strings (not arbitrary immutables)and we need to remember to open to access and close after changes unlike normal dictionariesthoughthe contents of file are retained between python program runs if we come back later and restart pythonour dictionary is still available againdbm files are like dictionaries that must be openedc:\pp \dbasepython import dbm file dbm open('movie'' 'file['batman' 'pow!open existing dbm file file keys(keys gives an index list [ 'cat-woman' 'batman' 'joker' 'robin'for key in file keys()print(keyfile[key] 'cat-womanb'splat! 'batmanb'pow! 'jokerb'wham! 'robinb'bang!notice how dbm files return real list for the keys callnot shown heretheir values method instead returns an iterable view like dictionaries furtherdbm files always store both keys and values as bytes objectsinterpretation as arbitrary types of unicode text is left to the client application we can use either bytes or str strings in our code when accessing or storing keys and values--using bytes allows your keys and values to retain arbitrary unicode encodingsbut str objects in our code will be encoded to bytes internally using the utf- unicode encoding by python' dbm implementation stillwe can always decode to unicode str strings to display in more friendly fashion if desiredand dbm files have keys iterator just like dictionaries moreoverassigning and deleting keys updates the dbm fileand we should close after making changes (this ensure that changes are flushed to disk)for key in fileprint(key decode()file[keydecode()cat-woman splatbatman powjoker wham databases and persistence