码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-09-13 17:48:32      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:切分   div   col   with   open   with open   pre   指定   line   

读取文件内容

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

 

写入文件:

# 追加写入到指定文件
str = "abcd"
with open(E:/test/test_en.txt, mode=a+, encoding="utf-8") as w:
     w.write(str + "\n")

 

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

标签:切分   div   col   with   open   with open   pre   指定   line   

原文地址:https://www.cnblogs.com/jumpkin1122/p/11516956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!