I need to read a csv on Python, and the text file that I have has this structure:
"114555","CM13","0004","0","C/U"@"99172","CM13","0001","0","C/U"@"178672","CM13","0001","0","C/U" delimeter: ,
newline: @
My code so far:
import csv data = [] with open('stock.csv') as csvfile: reader = csv.reader(csvfile, delimiter=',', lineterminator='@') for row in reader: data.append({'MATERIAL': row[0],'CENTRO': row[1], 'ALMACEN': row[2], 'STOCK_VALORIZADO' : row[3], 'STOCK_UMB':row[4]}) print(data) #this print just one row This code only print one row, because it's not recognize @ as a newline, and prints it with quotes:
[{'MATERIAL': '114555', 'CENTRO': 'CM13', 'ALMACEN': '0004', 'STOCK_VALORIZADO': '0', 'STOCK_UMB': 'C/U@"99172"'}]
quoting=csv.QUOTE_NONE"Instructs reader to perform no special processing of quote characters." If you want it without the quotes don't usecsv.QUOTE_NONE.lineterminatorwon't work. The docs say "The reader is hard-coded to recognise either '\r' or '\n' as end-of-line, and ignores lineterminator. This behavior may change in the future." This means you need to fix your data before thecsv.readergets to it.