EvilZone

Programming and Scripting => Scripting Languages => Topic started by: Ragehottie on June 03, 2012, 01:28:41 AM

Title: [Python] Write something to a file without deleting other things
Post by: Ragehottie on June 03, 2012, 01:28:41 AM
The title says it all. I want to write a new line of text without deleting the other lines.
Title: Re: [Python] Write something to a file without deleting other things
Post by: centizen on June 03, 2012, 01:59:27 AM
open the file with open("filename.txt","a") instead of using "w"


puts it in append mode
Title: Re: [Python] Write something to a file without deleting other things
Post by: Ragehottie on June 03, 2012, 02:08:17 AM
I still get an error. I am using this code:


Code: (python) [Select]

filename = 'Test.txt'


file = open(filename, 'a')
filestuff = file.read(1024)
print filestuff
file.write(filestuff + 'Hello\n')
file.close()


EDIT :
Ohhhhh. Nevermind