python - How to modify a text file? -
i'm using python, , insert string text file without deleting or copying file. how can that?
unfortunately there no way insert middle of file without re-writing it. previous posters have indicated, can append file or overwrite part of using seek if want add stuff @ beginning or middle, you'll have rewrite it.
this operating system thing, not python thing. same in languages.
what read file, make modifications , write out new file called myfile.txt.tmp or that. better reading whole file memory because file may large that. once temporary file completed, rename same original file.
this good, safe way because if file write crashes or aborts reason, still have untouched original file.
Comments
Post a Comment