Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x python-如何让其他人用三重引号检查信息_Python 3.x - Fatal编程技术网

Python 3.x 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

我正在为类中的每个函数编写详细信息,希望其他人在使用我的python代码时,可以使用类似
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
  • 如果需要格式良好的HTML或其他格式(如PDF),请使用

  • 您可能还希望删除docstring开头的空行;一些docstring解析代码可能会误解它。

    试试
    pydoc
    (或
    pydoc3
    )?pydoc只适用于那些内置python元素,不适用于我在这里创建的函数它对我来说很好。你试过了吗?如果pydoc对你来说很好,你能告诉我你是如何在我的
    stru进程
    函数中获得信息的吗?我试过了,它只告诉python内置元素我试着通过终端运行它,在我的代码文件text_preprocess.py的同一文件夹下,但它显示“preprocess.str_process._doc__;:command not found”。你知道我应该在哪里运行这个吗?@Cherry_-Wu这只能在Python脚本中运行。它不是明确的终端命令。您必须在终端内通过Python导入模块,并使用Python键入该模块。