我保留了一个输入字段,可以在其中浏览和选择CSV文件,并对文件进行解码并将值传递给相关字段。我现在收到的问题是像>>这样的值
['hello','"hello', 'world"']
CSV文件中的单元格值将类似于
col1 col2 col3 hello world hello,world
我尝试过的代码:
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)
输出为:
['hello','"hello', 'world"']
但是我想要:
['hello','"hello,world"']
我保留了一个输入字段,可以在其中浏览和选择CSV文件,并对文件进行解码并将值传递给相关字段。我现在收到的问题是[[hello','“ ...
如果您使用python中的csv,则必须像导入base64一样通过导入csv库来使用它。