替换python docstrings [英] Replacing python docstrings
问题描述
我已将 epytext 写入 reST 标记转换器,现在我想将我的整个库中的所有docstrings从epytext转换为reST格式。
I have written a epytext to reST markup converter, and now I want to convert all the docstrings in my entire library from epytext to reST format.
是否有一种聪明的方法来读取模块中的所有文档字符串并写回替换?
Is there a smart way to read the all the docstrings in a module and write back the replacements?
ps: ast 模块可能?
推荐答案
Pyment 是一种可以转换Python文本字符串并创建丢失的骨架的工具。它可以管理 Google , Epydoc (javadoc样式), Numpydoc , reStructuredText (reST,Sphinx默认)docstring格式。
Pyment is a tool that can convert Python docstrings and create missing ones skeletons. It can manage Google, Epydoc (javadoc style), Numpydoc, reStructuredText (reST, Sphinx default) docstring formats.
它接受单个文件或文件夹(也浏览子文件夹)。对于每个文件,它将识别每个docstring格式并将其转换为所需的格式。最后,将生成一个补丁以应用于该文件。
It accepts a single file or a folder (exploring also sub-folders). For each file, it will recognize each docstring format and convert it to the desired one. At the end, a patch will be generated to apply to the file.
- 安装Pyment
- install Pyment
键入以下内容(可以使用virtualenv)
Type the following (you can use a virtualenv):
$ git clone https://github.com/dadadel/pyment.git
$ cd pyment
$ python setup.py install
- 从Epydoc转换为Sphinx
- convert from Epydoc to Sphinx
您可以将项目转换为Sphinx格式(reST),这是默认的输出格式:
You can convert your project to Sphinx format (reST), which is the default output format, by doing:
$ pyment /my/folder/project
这篇关于替换python docstrings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!