[Tutor] adding more text to a file

Shizuha Aki shizuhaaki1 at yahoo.com
Sun Jan 17 18:40:23 CET 2010


Hi,

I am new to python, and i am trying to make a program that makes like a txt file database. so i have my whole program in a while True loop, it asks for information about the person and then writes the information about the person to a txt file, but i need it to be able to add more entries instead of just one.

my code is like this:

while True:
       name = raw_input("what is the name ")
       age = raw_input("what is the age ")

       out_file = open("persons.txt", "w")
       out_file.write("name: ")
       out_file.write(name)
       out_file.write("\n")
       out_file.write("age: ")
       out_file.write(age)
       out_file.write("\n")
       out_file.write("\n")
       out_file.close

now i want to add like say 5 persons to the txt file, but whenever i enter a new person it just overwrites the previous, im sure its because of the "w" but how exactly do i need to change my code to add more text instead of overwriting?



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100117/11f99350/attachment.htm>


More information about the Tutor mailing list