有没有一种方法可以为嵌套函数生成pydoc? [英] Is there a way to generate pydoc for nested functions?

查看:72
本文介绍了有没有一种方法可以为嵌套函数生成pydoc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为嵌套函数生成文档(在这种情况下为pydoc)的方法。 pydoc有可能吗?

I'm looking for a way to generate documentation, pydoc on this case, for nested functions. Is this possible with pydoc? Is it possible with other tools?

例如:

"""
Module docstring.
"""

def foo(x):
    """
    Foo does something.
    """
    ...

    def bar(y):
        """
        Bar does something
        """
        ...

使用以下命令生成pydoc:pydoc -w -filename-将为模块和foo()生成pydoc。但不适用于bar()。

Generating pydoc with: pydoc -w -filename- will generate pydoc for the module and foo() but not for bar().

通常没关系;问题是我正试图建立一个用于教育目的的图书馆,并且记录下封盖内部发生的情况特别有帮助。我想找到一种记录它的方法,而不必将内部函数暴露给全局范围。

Normally this would be ok; the problem is that I'm trying to build a library for educational purposes, and documenting what happens inside the closure is specially helpful. I want to find a way to document it without having to expose the inner functions to the global scope.

推荐答案

总是有手动方法:

"""
Module docstring.
"""

def foo(x):
    """
    Foo does something.
    N.B. Foo includes a local function bar() that does what bar does.
    """
    ...

    def bar(y):
        """
        Bar does something
        """
        ...

这不是自动的,但这确实意味着您的学生只会看到您希望他们看到的那些私有方法的文档。

It is not automatic but it does mean that your students only get to see documentation on those private methods that you wish them to see.

这篇关于有没有一种方法可以为嵌套函数生成pydoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆