小编Dib*_*ble的帖子

在python中制作csv文件时添加双引号

import csv
with open('innovators.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(["SN", "Name", "Contribution"])
    writer.writerow([1, "Linus Torvalds", "Linux Kernel"])
Run Code Online (Sandbox Code Playgroud)

我得到的输出:

SN, Name, Contribution
1, Linus Torvalds, Linux Kernel
Run Code Online (Sandbox Code Playgroud)

我想要的输出:

SN, Name, Contribution
1, Linus Torvalds, "Linux Kernel"
Run Code Online (Sandbox Code Playgroud)

所以,我尝试了

writer.writerow([1, "Linus Torvalds", "\"Linux Kernel\""])
Run Code Online (Sandbox Code Playgroud)

但这只是使它成为:

1, Linus Torvalds, ""Linux Kernel""
Run Code Online (Sandbox Code Playgroud)

我正在使用 Visual Studio Code 和 python 3,不知道如何让它输出带双引号的单词

python csv visual-studio-code

2
推荐指数
1
解决办法
4536
查看次数

标签 统计

csv ×1

python ×1

visual-studio-code ×1