Python csv.DictReader 参考
Python csv.DictReader 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
语法
import csv
rows = csv.DictReader(file)
参数
file:以newline=""打开的 CSV 文件对象。delimiter / quotechar:控制分隔符和引号规则。
返回值
返回行迭代器、字典行或写入结果;写入方法通常返回写入的字符数或 None。
示例
import csv
with open("data.csv", newline="", encoding="utf-8") as file:
for row in csv.DictReader(file):
print(row)
常见错误
- 打开文件时漏掉
newline="",Windows 下可能出现空行。 - 手动 split CSV 会处理不好引号、逗号和换行。
相关内容
相关内容
- Python collections.ChainMap 参考 Python collections.ChainMap 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.Counter 参考 Python collections.Counter 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.defaultdict 参考 Python collections.defaultdict 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.deque 参考 Python collections.deque 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.most_common 参考 Python collections.most_common 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.namedtuple 参考 Python collections.namedtuple 参考,整理标准库调用语法、参数、示例、返回值和常见错误。