+ 3

how to add a content in between a text ?

when we use write command it will delete the entire txt and replace with the msg how to add a content in between a text using append any one know pls share code.

29th May 2018, 3:51 PM
Aju George
Aju George - avatar
4 ответов
+ 1
you could just read the file, use string manipulation(list manipulation or whatever for bytes) and overwrite the contend with your data. or if you have big files: go to point using seek() read the file from wherever you want to insert, use string manipulation(or whatever) and write from point you want to insert to end.(so use seek() again and r+ mode) see this link: https://ubuntuforums.org/showthread.php?t=1847959
29th May 2018, 6:07 PM
Max
Max - avatar
+ 2
with open("test.txt", "a") as myfile: myfile.write("appended text") https://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file
29th May 2018, 4:09 PM
Max
Max - avatar
+ 2
this will add "appended text " in end of the file right? what if i need to put in middle of the text file?... i mean i want to put message in a particula byte onwards
29th May 2018, 5:52 PM
Aju George
Aju George - avatar
+ 1
thanku 😀
30th May 2018, 5:04 AM
Aju George
Aju George - avatar