Mega Code Archive

 
Categories / Python Tutorial / File
 

Opening and writing to a file

import sys try:    file = open( "clients.dat", "w" )   except IOError, message:                  print >> sys.stderr, "File could not be opened:", message    sys.exit( 1 ) print >> file, "account"        file.close()