当前位置: 代码迷 >> 综合 >> python 字符串按行写入txt
  详细解决方案

python 字符串按行写入txt

热度:54   发布时间:2024-01-19 23:12:39.0
for i in data:f = open('data.txt','a', encoding='utf-8')f.writelines(str(i))f.close()

 

注:data为写入的字符串,f.writelines为多变量一同输入(也可理解为字符串中按行输入),f.write为将字符串按字符输入。

       将字符串保存数组后写入,会缩短时间。

  相关解决方案