Python 将 数据list写入本地文件
''' 有⼀个数据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()
世界上最美的风景,是自己努力的模样