python将list列表元素写入文件自动换行的三种方式

  摘自 icon-default.png?t=LA92https://blog.csdn.net/ckq707718837/article/details/121276357

with open(cls_path,'w') as f1:
            #方法一:
        for line in cls_labelList:
            f1.write(line+'\n')
            #方法二:
#             lists=[line+"\n" for line in lists]
#            f1.writelines(lists)
            #方法三:
#             f1.write('\n'.join(lists))

你可能感兴趣的:(问题杂记,python,list)