python读取文件并写入内容到文件

读取文件内容

# 读取文件内容并按换行符切分
lines = open("data/voc01.txt", encoding="utf-8").read().split("
")

写入文件:

# 追加写入到指定文件
str = "abcd"
with open('E:/test/test_en.txt', mode='a+', encoding="utf-8") as w:
     w.write(str + "
")
原文地址:https://www.cnblogs.com/jumpkin1122/p/11516956.html