【发布时间】:2011-06-10 05:52:12
【问题描述】:
if data.find('!add') != -1:
f = open('masters.txt', 'w')
f.writelines(args, '\n')
sck.send('PRIVMSG ' + chan + ' :' + ' added' + " " + args + '\r\n')
f.close()
当我使用此代码时,它会用新数据替换旧数据,我怎样才能使新数据不替换旧数据而是在文件末尾结束。
【问题讨论】:
-
'w' 模式覆盖所有内容。 'a' 追加。享受:)
-
RTFM? docs.python.org/tutorial/inputoutput.html,第 7.2 节。