Author Topic: [Python] Write something to a file without deleting other things  (Read 1212 times)

0 Members and 1 Guest are viewing this topic.

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
The title says it all. I want to write a new line of text without deleting the other lines.
Blog: rexmckinnon.tumblr.com

Offline centizen

  • Peasant
  • *
  • Posts: 70
  • Cookies: 8
  • Certified Evil Genius
    • View Profile
Re: [Python] Write something to a file without deleting other things
« Reply #1 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

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] Write something to a file without deleting other things
« Reply #2 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
« Last Edit: June 03, 2012, 02:11:27 am by Ragehottie »
Blog: rexmckinnon.tumblr.com