gpt4 book ai didi

Python pydoc 用于 python 包

转载 作者:行者123 更新时间:2023-11-30 22:50:22 25 4
gpt4 key购买 nike

我正在尝试在init.py中记录一个python包,但我不清楚pydoc如何解析“”“三括号”“”注释以通过以下方式显示给用户:

>>> help(package)

$ pydoc package  

如何解析注释以在 pydoc 输出的 NAME 和 DESCRIPTION 部分中提供内容?我还可以填写其他部分,例如示例吗?

最佳答案

让我们考虑这个虚拟包:

./whatever
├── __init__.py
├── nothing
│   └── __init__.py
└── something.py

./whatever/__init__.py中我们有:

"""
This is whatever help info.

This is whatever description

EXAMPLES:
...
"""

__version__ = '1.0'

variable = 'variable'

现在运行 python shell:

➜  ~ python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import whatever
>>> help(whatever)

输出为:

NAME
whatever - This is whatever help info.

FILE
/home/el/whatever/__init__.py

DESCRIPTION
This is whatever description

EXAMPLES:
...

PACKAGE CONTENTS
nothing (package)
something

DATA
__version__ = '1.0'
variable = 'variable'

VERSION
1.0

您可以在描述部分提供示例。所以在 ./whatever/__init__.py 中。

希望有帮助。

关于Python pydoc 用于 python 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39393305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com