I'm currently using Python v2.10. I'm having trouble writing data to a csv file. Wondering if someone might be able to tell me what I am doing wrong. I'm getting the following error: "TypeError: list indices must be integers, not tuple" - not sure how to correct this. Also, I thought to write to a csv file, the data must be in string format ?
Ideally I would like each row to be like: Name, X1, Y1, X2, Y2, X3, Y3
Here is the code I have:
import csv
def main():
my_coords = open('Geo_Coords.csv', 'a')
coords = csv.reader(my_coords)
how_many = raw_input("How many Geometries do you wish to enter? ")
counter = 0
coords = []
while counter < how_many:
geometry = raw_input("Geometry Name ")
first_coordE = raw_input("1st Co-ord (Easting) ")
first_coordN = raw_input("1st Co-ord (Northing) ")
sec_coordE = raw_input("2nd Co-ord (Easting) ")
sec_coordN = raw_input("2nd Co-ord (Northing) ")
third_coordE = raw_input("3rd Co-ord (Easting) ")
third_coordN = raw_input("3rd Co-ord (Northing) ")
counter = counter + 1
my_coords.write(coords[[geometry],[first_coordE,first_coordN], [sec_coordE,sec_coordN], [third_coordE,third_coordN]] )
my_coords.close()
print my_coords
main()
coords[[geometry],[first_coordE,first_coordN], [sec_coordE,sec_coordN], [third_coordE,third_coordN]]. You're creating a tuple[geometry],[first_coordE,first_coordN], [sec_coordE,sec_coordN], [third_coordE,third_coordN], then using that to index the listcoords. What were you trying to do with that tuple/list of lists?