Python 3.x python-如何让其他人用三重引号检查信息
我正在为类中的每个函数编写详细信息,希望其他人在使用我的python代码时,可以使用类似Python 3.x python-如何让其他人用三重引号检查信息,python-3.x,Python 3.x,我正在为类中的每个函数编写详细信息,希望其他人在使用我的python代码时,可以使用类似help(function\u name) 例如,我创建了一个名为text_preprocess.py的python文件,在这个文件中我创建了一个包含函数的类 class Preprocess(): def str_process(self, row_string): ''' This Standford CoreNLP package requires the tex
help(function\u name)
例如,我创建了一个名为text_preprocess.py的python文件,在这个文件中我创建了一个包含函数的类
class Preprocess():
def str_process(self, row_string):
'''
This Standford CoreNLP package requires the text input as 1 single string.
The input annotators are in you command line input.
:param row_string: The string format input for Standford CoreNLP
:return: Json format output
'''
parsed_json = self.nlp.annotate(row_string, properties={
'annotators': self.standford_annotators,
'outputFormat': 'json'
})
return parsed_json
在这个函数中,您可以看到信息包含在三个引号中。
但我不知道其他用户如何在不查看我的代码的情况下看到这些信息
我在网上查看了很多解决方案,人们使用help(function\u name)
,但似乎他们是通过终端编写代码的,然后键入help(function\u name)
,这些示例中的许多都没有类。通过命令行使用--help
,只会给他们提供我通过argparse添加的参数描述
因此,如果我希望其他人可以在不查看代码的情况下检查我函数的信息,他们可以在哪里以及如何做到这一点?在类或方法的声明下方放置三重引号字符串称为文档。您可以使用
Preprocess.str\u process.\uu\u doc\uu
读取此文件
pydoc3 text\u preprocess
获取整个模块的文档。这递归地包括模块下面的所有项,例如类、它们的成员和函数pydoc3 text\u preprocess。如果您只需要类,请执行preprocess
pydoc3 text\u preprocess.preprocess.str\u process
您可能还希望删除docstring开头的空行;一些docstring解析代码可能会误解它。试试
pydoc
(或pydoc3
)?pydoc只适用于那些内置python元素,不适用于我在这里创建的函数它对我来说很好。你试过了吗?如果pydoc对你来说很好,你能告诉我你是如何在我的stru进程
函数中获得信息的吗?我试过了,它只告诉python内置元素我试着通过终端运行它,在我的代码文件text_preprocess.py的同一文件夹下,但它显示“preprocess.str_process._doc__;:command not found”。你知道我应该在哪里运行这个吗?@Cherry_-Wu这只能在Python脚本中运行。它不是明确的终端命令。您必须在终端内通过Python导入模块,并使用Python键入该模块。