-2
     if data.find('!add') != -1:
       f = open('masters.txt', 'w')
       f.writelines(args, '\n')
       sck.send('PRIVMSG ' + chan + ' :' + ' added' + " " + args + '\r\n')
       f.close()

When I use this code it replaces the old data with the new data, how can I make it so that the new data doesnt replaced the old data but ends at the end of the file.

fmark
  • 54,196
  • 25
  • 97
  • 106
SourD
  • 2,569
  • 7
  • 26
  • 28

3 Answers3

7

use

f = open('masters.txt', 'a')

instead

EDIT: see here

erbridge
  • 1,376
  • 11
  • 27
5

f = open('masters.txt', 'a')

waffle paradox
  • 2,740
  • 17
  • 19
0

Opening the file in 'w' mode deletes everything and then writes new stuff. I've learned it the hard way ;)

Anyway, you should open it in 'a' mode (append), which would look like this:

f = open("masters.txt", 'a')
f.writelines(args, "\n")
f.close()
Gloripaxis
  • 939
  • 1
  • 8
  • 8