print(key'=>'db[key]iteratefetchprint sue jones =[personjob=devname=sue jonespay= tom jones =[managerjob=mgrname=tom jonespay= bob smith =[personjob=nonename=bob smithpay= for key in sorted(db)print(key'=>'db[key]iterate by sorted keys bob smith =[personjob=nonename=bob smithpay= sue jones =[personjob=devname=sue jonespay= tom jones =[managerjob=mgrname=tom jonespay= notice that we don' have to import our person or manager classes here in order to load or use our stored objects for examplewe can call bob' lastname method freelyand get his custom print display format automaticallyeven though we don' have his person class in our scope here this works because when python pickles class instanceit records its self instance attributesalong with the name of the class it was created from and the module where the class lives when bob is later fetched from the shelve and unpickledpython will automatically reimport the class and link bob to it the upshot of this scheme is that class instances automatically acquire all their class behavior when they are loaded in the future we have to import our classes only to make new instancesnot to process existing ones although deliberate featurethis scheme has somewhat mixed consequencesthe downside is that classes and their module' files must be importable when an instance is later loaded more formallypickleable classes must be coded at the top level of module file accessible from directory listed on the sys path module search path (and shouldn' live in the topmost script filesmodule __main__ unless they're always in that module when usedbecause of this external module file requirementsome applications choose to pickle simpler objects such as dictionaries or listsespecially if they are to be transferred across the internet the upside is that changes in class' source code file are automatically picked up when instances of the class are loaded againthere is often no need to update stored objects themselvessince updating their class' code changes their behavior shelves also have well-known limitations (the database suggestions at the end of this mention few of thesefor simple object storagethoughshelves and pickles are remarkably easy-to-use tools updating objects on shelve now for one last scriptlet' write program that updates an instance (recordeach time it runsto prove the point that our objects really are persistent--that their current values are available every time python program runs the following fileupdatedb pyprints the database and gives raise to one of our stored objects each time if step (final)storing objects in database