我们使用的库是markdown_strings

pip install markdown_strings

程序如下:

from markdown_strings import header, table, code_block

with open("mark_down.md", 'w', encoding="utf8") as file:
    file.write(header("一级目录", 1) + "\n")
    file.write("这是一个文本\n")
    file.write(code_block("import pandas as pd\npd.DataFrame()", "python") + "\n")
    file.write(table([["列1", "1-1", "1-2", "1-3"],
                      ["列2", "2-1", "2-2", "2-3"],
                      ["列3", "3-1", "3-2", "3-3"],
                      ["列4", "4-1", "4-2", "4-3"]]))

得到输出结果,效果图如下:

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐