用Python在单元格中编写带有逗号和双引号的csv文件
在Python中更正csv文件时,我尝试在单元格中支持双引号和逗号。这是我写csv文件的代码用Python在单元格中编写带有逗号和双引号的csv文件,python,csv,Python,Csv,在Python中更正csv文件时,我尝试在单元格中支持双引号和逗号。这是我写csv文件的代码 def writecsv(filename): if(re.match('.csv$', filename)): filename = re.sub('\w+', filename) try: csvfile = open(filename, 'w', newline='') csvwriter = csv.writer(csvfile, del
def writecsv(filename):
if(re.match('.csv$', filename)):
filename = re.sub('\w+', filename)
try:
csvfile = open(filename, 'w', newline='')
csvwriter = csv.writer(csvfile, delimiter=',')
for row in spreadsheet[3]:
csvwriter.writerow(row)
csvfile.close()
except:
print('The file "'+filename+'" did not save correctly please try again')
现在如果有双引号,它将结束单元格,那么我如何跳过其中一个双引号?每个单元格都包含在一个列表中 查看CSV库的文档,您似乎需要定义一个方言对象,该对象允许您定义如何处理引号,并将其传递给CSV编写器。什么是电子表格?