代码点读机 / Python / csv

csv Python · 常用模块

读写逗号分隔表格文件的工具。

怎么用

import csv

小例子

import csv
import io
s = io.StringIO()
csv.writer(s).writerow(['x', 1])
print(repr(s.getvalue()))

运行结果

'x,1\r\n'

提醒:写文件时记得加 newline=''。

官方文档:https://docs.python.org/zh-cn/3/library/csv.html

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条