写出去的 CSV 有几行

👁️ 2 人浏览 💬 0 人评论 ❤️ 添加收藏

用 DictWriter 把汇总表写进一个内存文件,再读回来数行。运行程序:

import csv, io

table = [{"store": "东门", "total": 44.0}, {"store": "西门", "total": 38.0}, {"store": "北门", "total": 10.0}]
buf = io.StringIO()
w = csv.DictWriter(buf, fieldnames=["store", "total"], lineterminator="\n")
w.writeheader()
w.writerows(table)
text = buf.getvalue()
print(str(len(text.strip().split("\n"))) + "/" + text.split("\n")[0])
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论