# working with files # pmb 10/1/02 # open existing file for reading myfile = open ( 'hithere.txt', 'r' ) s = myfile.readline() print "read line ",s electionYears = myfile.readline() print electionYears # formatted strings # spose you have a number you wish to put in a string string = "Your score is %d points" % 10 print string string2 = "Fight,fight for %s " % "Minnesota" print string2 string3 = "The plane is %f meters above ground" % 2000 print string3 # now open a new file to write to outfile = open ('outfile.txt', 'w') outfile.write ( 'this goes to the output file' ); positions = [ 0.12, 98.23, 87.2 ] outfile.write ( "\nfirst position is %e" % positions[0] ) outfile.write ( electionYears ) print "done!"