How to write data in to the text file after printing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to write data in to the text file after printing?

I am trying to print the data and store it in a text file. So, Here is the code that I followed. If I am using this I can not be able to write the output into the text file. However, I am using 'a+' option instead 'w'It is appending the output. But I need the output to be stored only once. with open('new.txt' , 'w') as file: file.write(out) Where out is the output of the previous file Any suggestions regarding this would be appreciated.

5th Jun 2020, 8:31 AM
Dazzling_snug
Dazzling_snug - avatar
1 Answer
+ 8
It would be a good idea if you could show us the complete code. Please store it in playground and link it here. I am also not sure what you mean when you are talking about "... previous file...". Thanks!
5th Jun 2020, 8:37 AM
Lothar
Lothar - avatar