我正在处理CSV文件。如何在数组之间添加双引号?
marketplaces = ['amazon', 'ebay', 'alibaba', 'walmart']
with open('example.csv', 'a', encoding="utf-8") as f:
# Writing data to a file
writer = csv.writer(f, delimiter=",", quotechar='"', lineterminator="n", quoting=csv.QUOTE_ALL)
writer.writerow(marketplaces)
打印
"amazon","ebay","alibaba","walmart"
我想要这个
"amazon,ebay,alibaba,walmart"
完成!
marketplaces = ['amazon', 'ebay', 'alibaba', 'walmart']
with open('example.csv', 'a', encoding="utf-8") as f:
# Writing data to a file
f.write('"')
for marketplace in marketplaces:
if marketplace != marketplaces[len(marketplaces)-1]:
f.write(marketplace + ",")
else:
f.write(marketplaces)
f.write('"n')
输出
"amazon,ebay,alibaba, walmart"