Help with csv - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help with csv (/thread-8224.html) |
Help with csv - perrud - Feb-10-2018 I'm learning progamming, so i start to learn about CSV, but when I tryed to make something with that i noobed. Basically I make a progam who you can creat a csv file with name, price and importance of a product. But when i try to print a list after that fail. Code # Vinicius Perrud import csv #def listcreator for creat lists def listCreat(): nomedalista = input('Insira um nome para a lista de compras: ') p = str(input('Peça: ')) p = p.split(' ') d = str(input('Custo : ')) d = d.split(' ') i = str(input('Importancia: ')) i = i.split(' ') csvfile = open((nomedalista + '.csv'), 'w') filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) filewriter.writerow(['Item ', 'Custo ', 'Importância ']) # filewriter.writerow([p, d, i]) a = len(p) - 1 while a >= 0: filewriter.writerow([p[a], d[a], i[a]]) a = a - 1 #def printList for print a list def printList(): nome = str(input('Nome da lista: ')) nome = nome + '.csv' myFile = open(nome, 'r') reader = csv.reader(myFile) for row in reader: reader[row] = 'banana' print(reader) listCreat() printList()Error Someone know what is wrong??
RE: Help with csv - DeaD_EyE - Feb-10-2018 You can't write to a reader. The assignment in line 31 is not supported. If you just want to print out, change the lines 31,32 to: print(row) |