简体   繁体   中英

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:

>>> 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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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