简体   繁体   English

将双引号写入 Csv Python CSV 模块时出错

[英]Error Writing Double Quotes to Csv Python CSV Module

I'm trying to write an output to csv using the csv writer module.我正在尝试使用 csv 编写器模块将 output 写入 csv 。 I'm getting this Instead of double quotes (") I am getting this type of char (‚Äú)我得到这个而不是双引号 (") 我得到这种类型的字符 (‚Äú)

They should be like this The right output他们应该是这样的吧 output

My code (NOTE: I already tried adding encoding='utf-8 in the with open() statement and even tried adding .encoding('utf-8) in looping the 'key' but still having the same wrong output.我的代码(注意:我已经尝试在with open()语句中添加encoding='utf-8 ,甚至尝试在循环“密钥”时添加.encoding('utf-8)但仍然有相同的错误 output。

My code:我的代码:

with open('word_count.csv', 'w') as f:
    csv_writer = writer(f)
    for k,v in new_dict.items():
        csv_writer.writerow([k, v])

You can first encode the value of k,v and then add this to CSV.您可以先对 k,v 的值进行编码,然后将其添加到 CSV。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM