简体   繁体   English

如何在python中删除双引号?

[英]How to remove double quotes in python?

当我尝试创建一个新的csv文件并向其中添加行时,它将在每行的开头和结尾添加““”。如何解决此问题?

创建传递此kwarg的 csv 编写器

csv.writer(fileobj, quoting=csv.QUOTE_NONE)

Instead of using the csv library, you could simply output the file as such: 除了使用csv库,您还可以像这样简单地输出文件:

>>> x = [1,2,3,4,5]
>>> x = map(str,x)
>>> with open('out.csv','w') as fout:
...     fout.write(','.join(x))
... 
>>> with open('out.csv','r') as fin:
...     print fin.read().split(',')
... 
['1', '2', '3', '4', '5']

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

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