Python Open a txt file without clearing everything in it?

后端 未结 4 2002
孤城傲影
孤城傲影 2020-12-07 02:38
file = io.open(\'spam.txt\', \'w\')
file.write(u\'Spam and eggs!\\n\')
file.close()

....(Somewhere else in the code)

file = io.open(\'spam.txt\', \'w\')
file.write         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-07 03:05

    file = io.open('spam.txt', 'a')
    

    Use mode 'a' for Append.

提交回复
热议问题