import sys path = "/home/slin/enduro-trails/prototype/static/index.html" with open(path, 'r') as f: lines = f.readlines() # Insert after line 46 (0-indexed: 45) which is for terrain-tri insert_after = 45 new_lines = [ '