python | save the list data line by line in txt format and read it

Save

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

Read

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

Guess you like

Origin blog.csdn.net/weixin_43236007/article/details/108007898