Q:

adding two blank lines in the last of each text file

I have a few text files and need to add two extra blank lines in the last of each file. Following script adds one blank line (with one space) in the last of each text file. How to add one more blank line? Thanks a lot in advance.
  import glob
  for file in glob.glob("*.txt"):
      with open(file, "a") as f:
          f.write(" ")
          f.write(" ")
          f.close()

A:

f.write() does not automatically add a newline to your files, you have to add the newline yourself.
Also, you do not need to do f.close() , that is handled by the with statement.
Example -
import glob
for file in glob.glob("*.txt"):
    with open(file, "a") as f:
        f.write("\n\n")

