How do I write data into CSV format as string (not file)?

后端 未结 6 1351
借酒劲吻你
借酒劲吻你 2020-11-28 04:56

I want to cast data like [1,2,\'a\',\'He said \"what do you mean?\"\'] to a CSV-formatted string.

Normally one would use csv.writer() for

6条回答
  •  粉色の甜心
    2020-11-28 05:26

    import csv
    from StringIO import StringIO
    with open('file.csv') as file:
        file = file.read()
    
    stream = StringIO(file)
    
    csv_file = csv.DictReader(stream)
    

提交回复
热议问题