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

后端 未结 6 1364
借酒劲吻你
借酒劲吻你 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:34

    You could use StringIO instead of your own Dummy_Writer:

    This module implements a file-like class, StringIO, that reads and writes a string buffer (also known as memory files).

    There is also cStringIO, which is a faster version of the StringIO class.

提交回复
热议问题