import pypandoc middle = pypandoc.convert_file("body.md", "html") with open("top.html", "r") as top: with open("bottom.html", "r") as bottom: with open("index.html", "w") as index: index.write(top.read()) index.write(middle) index.write(bottom.read()) index.close()