简体   繁体   中英

Write each var input on a new line in a text file

I would like to know how I can make this irc 'bot' log to a text file.

I used:

  text_file = open("log.txt", "w")
  text_file.write(ircmsg +"\r\n")
  text_file.close()

The problem is that this code will make new input overwrite the textfile, while I want every new input a new line in the same text file.

(I know there are 'made bots' on the internet, but I prefer making it myself.)

您正在以“写入”模式打开文件,每次以“追加”模式打开文件时都会覆盖文件,即使用'a'代替'w'更多详细信息,请参见http://docs.python.org/2/tutorial/inputoutput。 HTML#读取与写入文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM