0
点赞
收藏
分享

微信扫一扫

Python 将 数据list写入本地文件

女侠展昭 2022-08-29 阅读 67

'''
有⼀个数据list of dict如下
a = [
{"yoyo1": "123456"},
{"yoyo2": "123456"},
{"yoyo3": "123456"},
]
写⼊到本地⼀个txt⽂件,内容格式如下:
yoyo1,123456
yoyo2,123456
yoyo3,123456

'''

def test():

a = [
{"yoyo1": "123456"},
{"yoyo2": "123456"},
{"yoyo3": "123456"},
]

# 打开一个名为 test.txt的文件,如果文件不存在,则自动创建

with open('test1.txt','w') as f:

for i in a:

for key,value in i.items():

f.write("{0},{1}\n".format(key,value))
print("{0},{1}\n".format(key,value))



test()

Python  将 数据list写入本地文件_数据

 

 

世界上最美的风景,是自己努力的模样



举报

相关推荐

0 条评论