How to append text in file without deleting initial text | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to append text in file without deleting initial text

in python when I am writing some text in a file with file.write() the initial text present in the file are deleted.....how to append some text in file without deleting the initial text.....??

30th Jun 2017, 6:51 AM
Arkojit Das
Arkojit Das - avatar
2 Answers
0
use the append flag for when you open your file. mode='a' the other flag options are here if you search the page for the 'open' function https://docs.python.org/3/library/functions.html#open
30th Jun 2017, 6:58 AM
richard
0
thanx richard for your help
30th Jun 2017, 7:00 AM
Arkojit Das
Arkojit Das - avatar