当前位置:主页 > 软件编程 > Python代码 >

对python的文件内注释 help注释方法

时间:2021-09-01 09:00:08 | 栏目:Python代码 | 点击:

目的:

在help(模块名)时,能够看见文件里面的注释。

首先,在文件的最开头,如果有个多行注释(三引号),就会将注释写入__DOC__变量,在help查看时,可以看见这个变量。

如果还需要输出函数,则可以将函数放入__all__变量。

__all__ = ['search','fix','hello','parser']

all里面的元素是唯一的,所以,这里要避免函数重名。当然,python对函数的重载也不是很提倡……

这样在python命令行,可以看见注释了。

比如一个程序是test02.py,先import它,再看

help(test02)

或者在程序中调用print(help(test02))

源代码:

#test02.py
"""
author:Zhao Zhenyu
this is an absolute test program.
"""
__all__ = ["function1", "function2"]
def function1():
pass
def function2():
"""2nd
"""
pass

执行情况:

>>> import test02
>>> help(test02)
Help on module test02:
NAME
test02
DESCRIPTION
author:Zhao Zhenyu
this is an absolute test program.
FUNCTIONS
function1()
function2()
2nd
DATA
__all__ = ['function1', 'function2']
FILE
c:\users\lenovo\documents\python scripts\python_spider\csdn例子\test02.py
>>>

您可能感兴趣的文章:

相关文章