Mega Code Archive

 
Categories / Python Tutorial / Database
 

Reading a shelve file

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()