+ 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.
4 Antworten
+ 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
+ 2
with open("test.txt", "a") as myfile:
myfile.write("appended text")
https://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file
+ 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
+ 1
thanku 😀