Content-Length: 65300 | pFad | https://mofanpy.com/tutorials/python-basic/basic/read-file2

读写文件 2 | 莫烦Python 读写文件 2
切换视频源:

读写文件 2

作者: Huanyu Mao 编辑: 莫烦 发布于: 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') 打开类型为 aa 即表示 append
  • 可以思考,如果用 w 形式打开,运行后会发生什么呢?

降低知识传递的门槛

莫烦经常从互联网上学习知识,开源分享的人是我学习的榜样。 他们的行为也改变了我对教育的态度: 降低知识传递的门槛

我组建了微信群,欢迎大家加入,交流经验,提出问题,互相帮持。 扫码后,请一定备注"莫烦",否则我不会同意你的入群申请。

wechat








    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://mofanpy.com/tutorials/python-basic/basic/read-file2

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy