Just wondering if anybody here knows how to write user entered data (stored through raw_input) into a specified column and row combination in a .csv file?
This is what I have attempted so far.
import csv
#READS FROM THE FINAL THIRD FILE
#WRITES TO THE FINAL THIRD FILE
file1 = csv.reader(open('test1.csv', 'rb'), delimiter=',')
ofile = open('new.csv', "wb")
writer = csv.writer(ofile, delimiter=',', quotechar='"')
studentnum = raw_input("Enter Student Number:")
col = raw_input("Enter Column:")
result = raw_input("New Result:")
acol = int(col)
aresult = int(result)
file1listnames = []
for row in file1:
file1listnames.append(row[0])
if studentnum in file1listnames:
for row in file1:
row[col] = result
writer.writerow([result])
else:
print 'The student number %s was not found' % studentnum
ofile.close()
I this current format it will write the user result by default to A0, I have been tinkering with this bit of code though and what I thought might work was
for row in file1:
row[col] = result
writer.writerow(row)
But, that doesn't work, and I figured it would write that for an entire column.
SO I guess atm I am just trying to get the specific column part down, then I can move onto the row.
Any pointers / advice would be appreciated. Thankyou!

New Topic/Question
Reply




MultiQuote



|