【问题标题】:what does colon wrapped class mean in python comment?python注释中冒号包装的类是什么意思?
【发布时间】:2018-07-16 08:22:04
【问题描述】:

python 注释中冒号包裹的类 (:class:) 是什么意思?

例如,

class Optimizer(object):
    r"""Base class for all optimizers.
    Arguments:
        params (iterable): an iterable of :class:`torch.Tensor` s or
            :class:`dict` s. Specifies what Tensors should be optimized.
        defaults: (dict): a dict containing default values of optimization
            options (used when a parameter group doesn't specify them).
    """

    def __init__(self, params, defaults):
        self.defaults = defaults

它是特定于 pytorch 的语法,还是什么?

来源:https://github.com/pytorch/pytorch/blob/master/torch/optim/optimizer.py

【问题讨论】:

标签: python class pytorch


【解决方案1】:

这与 Python 或 Torch 无关。它是文档工具的语法;最有可能Sphinx

语法表示对另一个类的文档的交叉引用。当文档工具生成超链接输出(例如 HTML)时,此类引用会自动成为指向指定类的文档页面的链接。

对于狮身人面像,请参阅Cross-referencing syntax documentation;在那里你会看到 py:class: 作为类引用,但我们可以假设默认域设置为 Python,因此 :class: 也是有效的。

PyTorch 项目确实是uses Sphinx to generate the documenation。您可以将找到的来源与the resulting generated documenation进行比较;注意dicttorch.Tensor 是指向更多文档的超链接。

【讨论】:

    猜你喜欢
    • 2014-11-17
    • 2020-08-15
    • 2012-10-09
    • 2018-01-02
    • 2020-05-21
    • 1970-01-01
    • 2019-09-14
    • 2012-09-25
    • 2021-02-06
    相关资源
    最近更新 更多