Python 将节点添加到rst doctree并保存到文件
我想在doctree中插入一个自定义节点,并将这些更改保存到文件中。 我正在读取以下RST文件Python 将节点添加到rst doctree并保存到文件,python,docutils,Python,Docutils,我想在doctree中插入一个自定义节点,并将这些更改保存到文件中。 我正在读取以下RST文件 Hello World! ############ :date: 2010-10-03 10:20 :author: James Bond This is a test. 像这样: doctree = docutils.core.publish_doctree(open('test.rst').read()) 我现在想在docinfo中插入一个新节点:id:234123,并将其另存为test.
Hello World!
############
:date: 2010-10-03 10:20
:author: James Bond
This is a test.
像这样:
doctree = docutils.core.publish_doctree(open('test.rst').read())
我现在想在docinfo中插入一个新节点:id:234123,并将其另存为test.rst。但是怎么做呢?没有重组的文本编写器 请看下面的答案: 如果只是一个小改动,最好编写一个简单的函数,将文件作为文本行读取,并将其写入新的文本文件,在解析/写入过程中的某个点插入新行