how to add lines to existing file using python

前端 未结 3 1625

I already created a txt file using python with a few lines of text that will be read by a simple program. However, I am having some trouble reopening the file and writing ad

3条回答
  •  半阙折子戏
    2020-12-03 02:59

    Open the file for 'append' rather than 'write'.

    with open('file.txt', 'a') as file:
        file.write('input')
    

提交回复
热议问题