Opening and writing pickled object to a file. : CPickle : Database PYTHON TUTORIALS


PYTHON TUTORIALS » Database » CPickle »

 

Opening and writing pickled object to a file.


import sys, cPickle

try:
   file = open"users.dat""w" )   
except IOError, message:             
   print >> sys.stderr, "File could not be opened:", message
   sys.exit)

inputList = []

inputList.append"A" 
inputList.append"B" 
inputList.append"C" 

cPickle.dumpinputList, file )  

file.close()

# Reading and printing pickled object in a file.

try:
   file = open"users.dat""r" )
except IOError:
   print >> sys.stderr, "File could not be opened"
   sys.exit)
   
records = cPickle.loadfile 
file.close()

for record in records:         
   print record].ljust15 ),



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Database
» CPickle