import csv
# 读的数据结构
# data='''
# 1,2,3
# 4,5,6
# 7,8,9
# '''
with open("plain_f1.csv", "r", encoding="utf-8") as f:
data = f.read()
ls = [i.split(",") for i in data.strip().split("\n")]
print(ls)
# 写的数据结构
# ls = [[1, 2, 3],
# [4, 5, 6],
# [7, 8, 9]]
# ls = ["1,2,3",
# "4,5,6",
# "7,8,9"]
with open("plain_f1.csv", "w", encoding="utf-8") as f:
f.write("\n".join([",".join(i) for i in ls]))
for循环嵌套读写文本
最新推荐文章于 2024-09-04 23:56:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)