# L-37 MCS 275 Wed 14 Apr 2010 : tempdbadd.py # This script collects data for a database to record temperatures. # The data is stored in a file "temperatures.txt". Every line in # this file represents a dictionary with fields place, data, time, # and temperature. Only the temperature is held as a number, all # other fields in the dictionary are of type string. # The script opens the file in the append mode and in a loop the user # is asked if more data will be added. After the user answers with 'y', # the user is prompted to provide data for the fields. # The data is appended as one string to the file. file = open('temperatures.txt','a') data = {'place':'','date':'','time':'','temp':0} while True: c = raw_input('Add more data ? (y/n) ') if c != 'y' : break data['place'] = raw_input('give place : ') data['date'] = raw_input('give date : ') data['time'] = raw_input('give time : ') data['temp'] = input('give temperature : ') file.write(str(data) + '\n') file.close()