Reading a shelve file. : shelve « Database « Python Tutorial






import sys
import shelve

def outputLine( account, aList ):
   print account.ljust( 10 ),
   print aList[ 0 ].ljust( 10 ),
   print aList[ 1 ].ljust( 10 ),
   print aList[ 2 ].rjust( 10 )

try:
   creditFile = shelve.open( "credit.dat" )
except IOError:
   print >> sys.stderr, "File could not be opened"
   sys.exit( 1 )

for accountNumber in creditFile.keys():
   outputLine( accountNumber, creditFile[ accountNumber ] )

creditFile.close()








15.5.shelve
15.5.1.object returned by shelve.open is not an ordinary mapping
15.5.2.Storing Objects in a Shelve File
15.5.3.Changing Objects in a Shelve File
15.5.4.Writing to shelve file.
15.5.5.Reading a shelve file.
15.5.6.database based on shelve file