I have kept an input field where i can browse and select the CSV file, and decode the file and passing the values to relevant fields. The problem I am receiving now is the values like
['hello','"hello', 'world"']
The cell values in the CSV file will be like
col1 col2 col3
hello world hello,world
The code I have tried:
import base64
file_value = self.file_import.decode("utf-8")
filename, FileExtension = os.path.splitext(self.filename)
input_file = base64.b64decode(file_value)
lst = []
for loop in input_file.decode("utf-8").split("\n"):
l = loop.replace(u'\ufeff', '')
vals = l.replace('\r', '')
lst.append([vals])
# Deletes the heading of the csv file
lst.pop(0)
for res in lst:
if res[0]:
output = res[0].split(',')
print(output)
The output is:
['hello','"hello', 'world"']
But I want like:
['hello','"hello,world"']
csvto write and read CSV file - it should handle it.import csv,reader = csv.reader(open(filename))anddata = list(reader)