import csv, re, sqlite3 con = sqlite3.connect("database_modfire.db") cur = con.cursor() cur2 = con.cursor() cur3 = con.cursor() cur4 = con.cursor() cur5 = con.cursor() f = open("wood_total_init.txt", "w+") f2 = open("soilloss_total_init.txt", "w+") f3 = open("perc_r0_total_init.txt", "w+") f4 = open("perc_r5_total_init.txt", "w+") f5 = open("perc_r10_total_init.txt", "w+") for i in range(0, 1406): cur.execute("SELECT Presc, wood FROM wood_rewards where ug like "+str(i)) cur2.execute("SELECT Presc, Soilloss FROM soilloss where ug like "+str(i)) cur3.execute("SELECT Presc, perc_r0_total FROM perc_r0 where ug like "+str(i)) cur4.execute("SELECT Presc, perc_r5_total FROM perc_r5 where ug like "+str(i)) cur5.execute("SELECT Presc, perc_r10_total FROM perc_r10 where ug like "+str(i)) results = cur.fetchall() results2 = cur2.fetchall() results3 = cur3.fetchall() results4 = cur4.fetchall() results5 = cur5.fetchall() toWrite = '' toWrite2 = '' toWrite3 = '' toWrite4 = '' toWrite5 = '' currentP = results[0][0] for j in range(0, len(results)): if(results[j][0] == currentP): toWrite += str(results[j][1]) toWrite2 += str(-1*results2[j][1]) toWrite3 += str(1*results3[j][1]) toWrite4 += str(1*results4[j][1]) toWrite5 += str(1*results5[j][1]) else: toWrite = toWrite[:-1]+"," toWrite2 = toWrite2[:-1]+"," toWrite3 = toWrite3[:-1]+"," toWrite4 = toWrite4[:-1]+"," toWrite5 = toWrite5[:-1]+"," currentP = results[j][0] toWrite += str(results[j][1]) toWrite2 += str(-1*results2[j][1]) toWrite3 += str(1*results3[j][1]) toWrite4 += str(1*results4[j][1]) toWrite5 += str(1*results5[j][1]) f.write(toWrite + "\n") toWrite = '' f2.write(toWrite2 + "\n") toWrite2 = '' f3.write(toWrite3 + "\n") toWrite3 = '' f4.write(toWrite4 + "\n") toWrite4 = '' f5.write(toWrite5 + "\n") toWrite5 = ''