Append text at line 3 of an existing file python

Hi there,
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
Line 1…
Line2 …
I need to add new text here …
Line 4

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:

  1. open the file for reading;
  2. use readlines() to read each line all at once into a list;
  3. close the file;
  4. append to the third line in the list;
  5. open the file again for writing;
  6. write the modifid lines in the list back to the file.

Is that enough of a hint?