I am new to python and i need a simple python code to do the following.
append text at line 3 of an existing file python. For example
I need to add new text here …
Unfortunately files do not support inserting text in the middle of the
If the file is small, say less than 50 MB, probably the easiest thing to
do is to six steps:
- open the file for reading;
- use readlines() to read each line all at once into a list;
- close the file;
- append to the third line in the list;
- open the file again for writing;
- write the modifid lines in the list back to the file.
Is that enough of a hint?