-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
  • 57,259
  • 27
  • 100
  • 107
SourD
  • 2,771
  • 7
  • 28
  • 28

3 Answers3

7

use

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

instead

EDIT: see here

erbridge
  • 1,376
  • 12
  • 27
5

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

waffle paradox
  • 2,755
  • 18
  • 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
  • 1,026
  • 1
  • 9
  • 9