python | 将列表数据按行保存为txt格式并进行读取

保存

with open("abc.txt", 'w') as f:
    for i in alist:
        f.write(i+'\n')

读取

f = open("abc.txt","r")
lines = f.readlines()
for line in lines:
    line=line.strip('\n')# 删除\n
    print(line)

你可能感兴趣的:(列表,python,txt)