Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将节点添加到rst doctree并保存到文件_Python_Docutils - Fatal编程技术网

Python 将节点添加到rst doctree并保存到文件

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.

我想在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.rst。但是怎么做呢?

没有重组的文本编写器

请看下面的答案:

如果只是一个小改动,最好编写一个简单的函数,将文件作为文本行读取,并将其写入新的文本文件,在解析/写入过程中的某个点插入新行