Writing to the end of a text file in python 3

This question already has an answer here:

  • How do you append to a file? 8 answers

  • append mode打开文件

    open(filename, 'a')
    

    Just use append mode:

    with open('something.txt', 'a') as f:
        f.write('text to be appended')
    

    Documentation can be found here.


    Open your file with something like

    f = open('myfile.log', 'a')
    

    you can also check documentation for more alternatives

    链接地址: http://www.djcxy.com/p/42398.html

    上一篇: 写入文件(python)

    下一篇: 在python 3中写入文本文件的末尾