database programming in this we will implement two versions of program that maintains list of dvdsand keeps track of each dvd' titleyear of releaselength in minutesand director the first version uses dbm (via the shelve moduleto store its dataand the second version uses the sqlite database both programs can also load and save simple xml formatmaking it possiblefor exampleto export dvd data from one program and import it into the other the sql-based version offers slightly more functionality than the dbm oneand has slightly cleaner data design dbm databases bytes ||the shelve module provides wrapper around dbm that allows us to interact with the dbm as though it were dictionaryproviding that we use only string keys and picklable values behind the scenes the shelve module converts the keys and values to and from bytes objects the shelve module uses the best underlying dbm availableso it is possible that dbm file saved on one machine won' be readable on anotherif the other machine doesn' have the same dbm one solution is to provide xml import and export for files that must be transportable between machines--something we've done for this section' dvd programdvds-dbm py for the keys we use the dvdstitles and for the values we use tuples holding the directoryearand duration thanks to the shelve module we don' have to do any data conversion and can just treat the dbm object as dictionary since the structure of the program is similar to interactive menu-driven programs that we have seen beforewe will focus just on those aspects that are specific to dbm programming here is an extract from the program' main(functionwith the menu handling omitteddb none trydb shelve open(filenameprotocol=pickle highest_protocolfinallyif db is not nonedb close(here we have opened (or created if it does not existthe specified dbm file for both reading and writing each item' value is saved as pickle using the specified pickle protocolexisting items can be read even if they were saved using lower protocol since python can figure out the correct protocol to use for reading pickles at the end the dbm is closed--this has the effect of clearing the dbm' internal cache and ensuring that the disk file reflects any changes that have been madeas well as closing the file