读写文件 2
作者: 编辑: 莫烦 发布于: 2016-01-01
给文件增加内容¶
我们先保存一个已经有3行文字的 my file.txt
文件, 文件的内容如下:
This is my first test. This is the second line. This the third 然后使用添加文字的方式给这个文件添加一行 This is appended file.
, 并将这行文字储存在 append_file 里,注意\n的适用性:
总结¶
- 掌握 append 的用法 :
open('my file.txt','a')打开类型为a,a即表示 append - 可以思考,如果用
w形式打开,运行后会发生什么呢?