tags:

views:

187

answers:

2
while 1:
    text_file = open("write_it.txt", "w")
    word = input("Please add to a text file: ")

What else do I need to add to make my code run properly?

A: 

Not sure, but that open statement inside of the while couldn't be affecting its behaviour? Have you tried just moving it out of while loop?

Jesus Benito
i mean i need to continue this code to make a program thats writes everything to the "write_it.txt
i dont really understand, i tried to use "a" for open file and add somthing there but still its a blank txt file. please can you give me a full code of that programm
IF you get Aaron's code and instead of: word = input("Please add to a text file: ")you use:word = raw_input("Please add to a text file: ")It should work
Jesus Benito
It doesnt work :S
+2  A: 

This should work:

text_file = open("write_it.txt", "w")
while 1:
    word = input("Please add to a text file: ")
    if not word:
        break
    text_file.write(word)
text_file.close()
Aaron Digulla