python - 避免在 Sphinx 文档中扩展 sys.argv 关键字参数

标签 python python-sphinx

我有这样一个类

import sys

class ACommand(object):

    @classmethod
    def cmd(cls, argv=sys.argv):
        " Executes the command. "
        pass

当用 Sphinx 记录它时,它会将 sys.argv 扩展为其当前值,生成类似于以下签名的内容

classmethod cmd(argv=['/path/to/sphinx-build', '-b', 'html', '-d', '_build/doctrees', '.', '_build/html'])

我发现在文档中包含 sys.argv 比扩展更方便。我怎样才能做到这一点?

最佳答案

您可以创建一个代理对象,例如

class ListProxy(object):
    def __init__(self, l):
        self.list = l
    def __getitem__(self, i):
        return self.list[i]

然后

@classmethod
def cmd(cls, argv=ListProxy(sys.argv)):
    " Executes the command. "

或者,你可以做的更简单

@classmethod
def cmd(cls, argv=None):
    " Executes the command. "
    if argv is None:
        argv = sys.argv

关于python - 避免在 Sphinx 文档中扩展 sys.argv 关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12688368/

相关文章:

python - 阻止 Sphinx 执行缓存的类方法属性

python - 使用 setuptools 构建 sphinx 文档时如何将警告变成错误?

python - 具有日期列的 df 在当前和下一行的日期之间添加持续时间列

python - 使用 Sphinx 自动记录 Python

python - 与我的 PC 相比,Google Colab 非常慢

python - 如何在openCV中了解Orb输出中关键点和des的格式

python - 如何将自定义 css 文件添加到 Sphinx?

hyperlink - 在 Sphinx/reStructuredText 中添加在新标签页中打开的链接

python - 我如何将 'down grade' 转换为 python2.7

python - 在 Selenium 中更改 Google Chrome 用户代理的方法?