- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在要记录的项目中有一些 Python 代码,但是我在记录元组或列表类常量时遇到了问题。请参见下面的代码和图片。当每行上有多个项目并且行随机拆分时,很难阅读文档。
元组可以用另一种方式格式化吗?喜欢新行中的每个元素。我仍然想使用 autodoc(在整个文件上),所以手动添加类是 Not Acceptable 。我可以更改代码、conf.py 或自动模块选项。
首先:
.. automodule:: my_python_file
:members:
:undoc-members:
my_python_file.py:
class SOMinimalExample:
"""SO example with ugly formatted tuple"""
MY_CONSTANT = (
('AnElement', (1, 2, 3, 5)),
('AnotherElement', (3, 5)),
('MoreElements', (1, 5)),
('MoreElements', (1, 5, 5)),
('MoreElements', (213, )),
('MoreElements', (5, 1, 5)),
('MoreElements', (1, 8, 5)),
('MoreElements', (1, 0, 0, 0, 5)),
('MoreElements', (1, 123, 4324, 46, 845)),
)
输出:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SO documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="welcome-to-so-s-documentation">
<h1>Welcome to SO’s documentation!<a class="headerlink" href="#welcome-to-so-s-documentation" title="Permalink to this headline">¶</a></h1>
<div class="toctree-wrapper compound">
<span id="document-modules"></span><div class="section" id="so">
<h2>so<a class="headerlink" href="#so" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<span id="document-my_python_file"></span><div class="section" id="module-my_python_file">
<span id="my-python-file-module"></span><h3>my_python_file module<a class="headerlink" href="#module-my_python_file" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="my_python_file.SOMinimalExample">
<em class="property">class </em><code class="descclassname">my_python_file.</code><code class="descname">SOMinimalExample</code><a class="headerlink" href="#my_python_file.SOMinimalExample" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>SO example with ugly formatted tuple</p>
<dl class="attribute">
<dt id="my_python_file.SOMinimalExample.MY_CONSTANT">
<code class="descname">MY_CONSTANT</code><em class="property"> = (('AnElement', (1, 2, 3, 5)), ('AnotherElement', (3, 5)), ('MoreElements', (1, 5)), ('MoreElements', (1, 5, 5)), ('MoreElements', (213,)), ('MoreElements', (5, 1, 5)), ('MoreElements', (1, 8, 5)), ('MoreElements', (1, 0, 0, 0, 5)), ('MoreElements', (1, 123, 4324, 46, 845)))</em><a class="headerlink" href="#my_python_file.SOMinimalExample.MY_CONSTANT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html#document-index">SO</a></h1>
<h3>Navigation</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="index.html#document-modules">so</a></li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html#document-index">Documentation overview</a><ul>
</ul></li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2019, me.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.8.4</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
</div>
</body>
</html>
最佳答案
一个选项是使用 autoclass
并通过嵌套 literalinclude
指令。
.. autoclass:: my_python_file.SOMinimalExample
:members:
.. attribute:: MY_CONSTANT
Some doc text for MY_CONSTANT.
.. literalinclude:: ../src/my_python_file.py
:dedent: 4
:lines: 3-13
输出:
我希望以下内容会起作用(而不是使用行号):
.. literalinclude:: ../src/my_python_file.py
:pyobject: SOMinimalExample.MY_CONSTANT
但它不起作用。 Sphinx 发出警告:“在包含文件中找不到名为‘SOMinimalExample.MY_CONSTANT’的对象”。
关于python - Python autodoc 元组/列表格式可以更改吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54823758/
我试图理解基数排序,但在理解实现实际代码时改 rebase 数时遇到问题。这是我用来学习基数排序的代码,我会尝试解释我不明白的地方。 此代码由 GeeksForGeeks 提供: // C++ imp
话不多说,请看代码: ? 1
本文实例讲述了mysql语句实现简单的增、删、改、查操作。分享给大家供大家参考,具体如下: 1、创建db_shop数据库,如果该数据库不存在则创建 ?
使用oracle触发器 实现对某个表的增改删的监控操作,并记录到另一个表中。 代码: 复制代码代码如下: create or replace trigger test_trigge
java连接数据库增、删、改、查工具类 数据库操作工具类,因为各厂家数据库的分页条件不同,目前支持Mysql、Oracle、Postgresql的分页查询 在Postgresql环境测试过了,其他
1、修改数据 复制代码代码如下: DataRow dr =
注册表可以用来进行存储一些程序的信息,例如用户的权限、或者某些值等,可以根据个人需要进行存储和删减。 当前注册表主目录: 引用包 Wesky.Net.OpenTools 1.0.5或
是否可以将 pdf 页面的页眉更改为与当前所选书签同名的名称?我正在为我的 pdf 生成使用 Flying Saucer 。你能举个例子吗?提前致谢。 最佳答案 这对我适用于 flyingsaucer
好家伙,写后端,这多是一件美逝. 关于这个项目的代码前面的博客有写 我的第一个独立项目 - 随笔分类 - 养肥胖虎 - 博客园 (cnblogs.com
准备工作: 增、删、改、查的方法有很多很多种,这里只展示出常用的几种。 ?
需要5个类: 1.实体类:Person.java 2.抽象类:SQLOperate.java(封装了对数据库的操作) 3.助手类:DBOpenHelper.java(继承SQLiteOpenH
首先是是一个简单的例子,单链表的建立和输出。 程序1.1 复制代码 代码如下: #include<iostream> #include<string> using na
数据库操纵基本流程为: 1、连接数据库服务器 2、选择数据库 3、执行SQL语句 4、处理结果集 5、打印操作信息 其中用到的相关函数有 •resource m
我需要为 iPad 和 iPhone 设置不同颜色的标签,我知道我们可以为不同的尺寸类别更改字体大小,但是有什么方法可以根据尺寸类别的值设置不同的颜色 我知道有可用的代码解决方案,但我想知道 size
假设我有一个物体相对于相机的坐标 X、Y、Z 和方向 Rx、Ry、Rz。此外,我有这个相机在世界上的坐标 U、V、W 和方向 Ru、Rv、Rw。 如何将对象的位置(位置和旋转)转换为其在世界中的位置?
CRUD是Create(创建)、Read(读取)、Update(更新)和Delete(删除)的缩写,它是普通应用程序的缩影。如果您掌握了某框架的CRUD编写,那么意味可以使用该框架创建普通应用程序了
项目结构: 添加页面: &
本文实例讲述了android操作sqlite数据库(增、删、改、查、分页等)及listview显示数据的方法。分享给大家供大家参考,具体如下: 由于刚接触android开发,故此想把学到的基础知识
总括 pandas的索引函数主要有三种: loc 标签索引,行和列的名称 iloc 整型索引(绝对位置索引),绝对意义上的几行几列,起始索引为0 ix 是 iloc 和 loc的合体 at
我是一名优秀的程序员,十分优秀!