网络编程
位置:首页>> 网络编程>> Python编程>> 对python的文件内注释 help注释方法

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

作者:tjzzy  发布时间:2021-12-20 18:12:46 

标签:python,文件,注释,help

目的:

在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
>>>

来源:https://blog.csdn.net/tjzzy/article/details/70256155

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com