【问题标题】:Extract all docstrings (__doc__) from my Django files从我的 Django 文件中提取所有文档字符串 (__doc__)
【发布时间】:2018-09-29 04:25:31
【问题描述】:

我在 Django 中有一个项目,我在我的模块、类和函数中编写文档字符串。但我需要一种方法来自动从那里提取所有__doc__。像“python manage.py collectstatic”,但对于所有.py 代码的.__doc__ 实例。类似的东西?有什么想法吗?

【问题讨论】:

  • 您可能正在寻找pydoc
  • 如果您正在寻找 pydoc(听起来确实如此。)我建议您投入额外的精力让 sphinx 工作......你不会后悔的

标签: python django documentation docstring


【解决方案1】:

带你一睹pydoc

示例模块:

# foo.py

def bar():
  """this is the docstring for bar()"""
  print 'hello'


def baz():
  """this is the docstring for baz()"""
  print 'world'

现在您可以使用以下命令打印文档字符串:

$ pydoc foo.py
Help on module foo:

NAME
    foo

FILE
    /path/to/foo.py

FUNCTIONS
    bar()
        this is the docstring for bar()

    baz()
        this is the docstring for baz()

您还可以生成 HTML 帮助文件:

$ pydoc -w ./foo.py
wrote foo.html

看起来像这样:

【讨论】:

  • 是的,pydoc 是 util。但在 Python 3 中并没有那么多。例如,导入与 pydoc 有冲突。文本编码也是。
猜你喜欢
  • 1970-01-01
  • 2016-09-18
  • 1970-01-01
  • 2020-05-26
  • 1970-01-01
  • 1970-01-01
  • 2012-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多