This is what I'm working with. On line 43 you can see I'm writing a string to a text file. Once the script looks again I want it to write another string to the text file on another line. How would I do this?
Asked
Active
Viewed 779 times
0
-
Please post actual code in the question – OneCricketeer Apr 05 '17 at 03:43
-
Sorry. I will do that when I ask another question. – Misha Eide Apr 05 '17 at 03:44
-
No, please [edit] your current question – OneCricketeer Apr 05 '17 at 03:44
-
2Maybe you need to open the file in append mode, using `"a"` while opening the file to append the contents at the end of file – ZdaR Apr 05 '17 at 03:45
-
Possible duplicate of [How do you append to a file?](http://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file) – OneCricketeer Apr 05 '17 at 03:46
-
Anyway, this code will eventually crash with Stack limit exceeded... Learn about `while True` instead of calling `main()` inside of itself – OneCricketeer Apr 05 '17 at 03:47
1 Answers
0
You open the file, add the text and add the new line char...
Finally close the file too (you don't want to try to open a file that is already open :) )
x = open("myfile.txt","a")
x.write("the line here" + '\n')
x.close()
In your case
file = open("text.txt","a")
file.write(save + '\n') #here add the new line
file.close()
time.sleep(25)

ΦXocę 웃 Пepeúpa ツ
- 47,427
- 17
- 69
- 97