查看源代码,Pydoc您可以看到以下评论:
if all is not None:
# only document that which the programmer exported in __all__
return name in all
这意味着pydoc 将查找__all__模块属性,并且如果已定义,则只会记录其中定义的功能。
因此,对于您的模块,您可以通过指定它们的名称X来定义要导出的函数。__all__只有那些会记录在相应的功能部分:
__all__ = ['myfunc1', 'myfunc2', ..., 'myfuncN']
一个例子:
如果没有__all__,以下简单文件名为mod.py:
from math import cos
def myfunc():
""" documentation"""
pass
生成一个mod.html文件,其中包含用户定义myfunc() 和导入的内置函数的文档cos():

通过添加__all__和指定要在其中导出的函数名称:
__all__ = ['myfunc'] # visible names
from math import cos
def myfunc():
""" documentation"""
pass
您将“过滤掉”该cos()功能,并且只有以下文档myfunc():

注意: __all__可以包含脚本中使用的函数和变量名称。pydoc将区分这些并将它们分为两个不同的组:
- 函数中的函数
- 数据中的变量。