-2

say i already had a csv file with rows 0-3 filled in on 4 columns how do i write to the 4th row without overwriting the others using csv.writer

for example

Kieran,3,10,7

ben,4,8,5

ethan,9,1,4

a = c.writer(Class)
data = [[row[1],row[2],row[3],average]]
a.writerows(data)

oliver,7,2,3

how do i write a 4th number in? thanks to a different row in the same column

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Morgan Thrapp Dec 21 '15 at 20:49
  • 1
    Have you attempted this problem yourself yet? You should post your code rather than asking someone to write it for you. – tpearse Dec 21 '15 at 20:50
  • yeah it doesent let me codes on now – Kieran Ingram Dec 21 '15 at 20:50
  • no i need to write to a new row not a new columns but thanks – Kieran Ingram Dec 21 '15 at 20:56

1 Answers1

1

You need to open the file in "append mode" as indicated below.

f = open(file, 'a').write(what)
Russel204
  • 28
  • 7