Feb-10-2018, 06:12 PM
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
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
Error:Traceback (most recent call last):
File "/home/perrud/Documentos/Python/CSV Teste/ListManager.py", line 35, in <module>
printList()
File "/home/perrud/Documentos/Python/CSV Teste/ListManager.py", line 31, in printList
reader[row] = 'banana'
TypeError: '_csv.reader' object does not support item assignment
Someone know what is wrong??