Hi I am fairly new at pyhton and I am trying to create a program to append a new row of raw input to the bottom of my existing .csv file. So far I have this:
import csv
x=1
y=1
n=0
citiesx=[]
citiesy=[]
city_names=[]
total=input("How many cities do you have? ")
while x in range(0,total+1):
city_name=raw_input("What is the name of your city?<'0' exits> ")
if city_name==0:
break
else:
xcoord=input("What is the x coordinate?<'0' exits> ")
if xcoord==0:
break
else:
ycoord=input("What is the y coordinate?<'0' exits> ")
if xcoord==0:
break
else:
city_names.append(city_name)
citiesx.append(xcoord)
citiesy.append(ycoord)
x+=1
w = csv.writer(open('cities.csv','w'))
spamWriter = csv.writer(open('cities.csv', 'wb'), delimiter=' ',
quotechar=' ', quoting=csv.QUOTE_MINIMAL)
while y in range(0,total+1):
spamWriter.writerow([city_names[n]] + [','] + [citiesx[n]] + [','] + [citiesy[n]])
n+=1
y+=1
raw_input("press enter to exit")
That creates the .csv file which would look similar to this(commas meaning new cell):
a,1,2
b,3,4
c,5,6
d,7,8
What the next program would need to do is add another row of inputed data from the user i.e. e,9,10. I feel like I have tried everything to make this work. If anybody has some code to append a new row or can help me out that would be great.
Thanks,
Jaro