I have this CSV with me called task2.csv. The header is :Item and Description.
I am trying to add " i", " ink" to this csv using following csv python script. but it is adding to a wrong column and modify the last field.
Please help me make my script start from a fresh new row.
Things I tried:
- save the csv with pointer to the new row
- wrote twice ( the second time write function was called it worked correctly. the first write still modifies the last row but second write writes to the new row.
- checked stack overflow and modified the according to few suggestions ( Use dictReader and dictWriter) still did not work
My Code:
import csv
def readCsv(file):
dict = {}
with open(file) as csvdata:
csvReader = csv.DictReader(csvdata)
for row in csvReader:
print row['item'], row['description']
def writeCsv(file, field):
fieldnames = ['item', 'description']
with open(file, 'a') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writerow({'item': 'i', 'description': 'ink'})
writeCsv("task2.csv", "a")
readCsv("task2.csv")
ORGINAL CSV:
MODIFIED CSV:


python-2.7andpython-3.x?