相关疑难解决方法(0)

如何将变量放入Python docstring中

所以我正在尝试创建一个"动态"文档字符串,如下所示:

ANIMAL_TYPES = ["mammals", "reptiles", "other"]

def func(animalType):
""" This is a sample function.

    @param animalType: "It takes one of these animal types %s" % ANIMAL_TYPES
"""
Run Code Online (Sandbox Code Playgroud)

基本上让文档字符串@param animalType显示任何ANIMAL_TYPES有; 这样当更新此变量时,docstring将自动更新.

然而不幸的是,它似乎没有用......有谁知道是否有办法实现这一目标?

python docstring

46
推荐指数
3
解决办法
2万
查看次数

有没有办法让类继承sphinx的超类文档?

假设我有一堂课

class A(object):
  def myfunction():
    """A."""
    pass
Run Code Online (Sandbox Code Playgroud)

和一个子类

class B(A):
  def myfunction():
    pass
Run Code Online (Sandbox Code Playgroud)

是否可以使用sphinx从A.myfunction继承B.myfunction的API文档?B.myfunction的文档应为"A".同样.

python python-sphinx

4
推荐指数
1
解决办法
1375
查看次数

标签 统计

python ×2

docstring ×1

python-sphinx ×1