如何用注释描述python脚本?

如何用注释描述python脚本?,python,Python,我有一个可以完全独立运行的Python脚本。我想创建一个脚本在注释中的一般描述 什么是蟒蛇式的方法?这和我下面的例子一样吗?不知怎的,在进口之前就有这种感觉是不对的,但我不确定 例如,我有: """ This is the example description """ import argparse from datetime import datetime import re import sys from xml.etree import ElementTree def some f

我有一个可以完全独立运行的Python脚本。我想创建一个脚本在注释中的一般描述

什么是蟒蛇式的方法?这和我下面的例子一样吗?不知怎的,在进口之前就有这种感觉是不对的,但我不确定

例如,我有:

"""
This is the example description
"""

import argparse
from datetime import datetime
import re
import sys
from xml.etree import ElementTree


def some functions():
    x = x+1
使用标签。以hashtag开头的行不作为代码读取

"""
Here you can add the copyright contents
This is the overall description of this script 
And the available classes/functions in this script
You can also add usage
"""

import argparse
from datetime import datetime
import re
import sys
from xml.etree import ElementTree


def some functions():
    """
    This is function related description what is this function and how it works
    You can also add expected input and output information
    """
    x = x+1 #adding 1 in the input
    # comment for the below complicated logic
    # Explain the below logic
    x = x*x*1*2*x 
有关更多注释和实践,请参见此模板。

使用此模板:

"""
Author: YOU
"""

import argparse
from datetime import datetime
import re
import sys
from xml.etree import ElementTree


def some functions():
    """
    This is a description .....
    """
    x = x+1 #adding 1 in the input (this is a comment)
这就是我们要说的:

独立程序脚本的docstring应该可用作 它的用法消息,在使用不正确的命令调用脚本时打印 或者缺少参数,或者可能带有-h选项,以寻求帮助。这样的 docstring应该记录脚本的函数和命令行 语法、环境变量和文件。使用情况消息可以相当简单 精心设计几个完整的屏幕,应足以满足新的需求 用户可以正确使用该命令,以及进行完整的快速 对复杂用户的所有选项和参数的引用


第一件事:请注意,三重引号字符串不是注释,它们是真正的Python字符串。碰巧它们也常用于docstring docstring是模块、类或函数开头的字符串,Python将其用作此模块/类/函数的帮助字符串,因为这里通常需要多行,但任何字符串都可以

当然,注释是以a开头的行,python完全忽略了注释

现在你说:

我想创建一个脚本在注释中的一般描述


如果您真正想要的是注释,请使用注释语法。如果您想要的是Python可以用于ie import yourmodule等文档的东西;帮助模块;,然后使用docstring。

这是python的方式。我会使用hashtag。