写出去的 CSV 有几行
用 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])
全部评论