I am trying to convert a csv file into another file (file type doesn't matter as the program using the converted data just opens it like a text file).
So far I have managed to convert and print the original csv data into the the data structure I want but I now need to save that as another file.
import csv
file = open('newData', 'w')
with open('initialData.csv', 'rb') as f:
reader = csv.reader(f, delimiter=',', quotechar='|')
for row in reader:
print row[13] + ' 1:' + row[0] + ' 2:' + row[1]
file.write(f)
file.close()
Whenever I run this I get the error:
TypeError: expected a character buffer object
I know there is nothing wrong with converting the csv file as that prints fine when I comment out the file.write(f).
Many thanks in advance!
with..asfor the output file as well. Also, don't name themfile(that's a built-in) andf. Use something likeinfileandoutfile.