Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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
生成脚本';在IPython中设置帮助字符串_Python_String_Ipython_Documentation - Fatal编程技术网

生成脚本';在IPython中设置帮助字符串

生成脚本';在IPython中设置帮助字符串,python,string,ipython,documentation,Python,String,Ipython,Documentation,假设mycode.py具有以下通用结构: import bla import bla def function: bla bla description="""My multi-line description of the code """ import bla more code here IPython中的哪个命令将打印“description=”中给出的帮助字符串 这里的所有相关问题似乎都表明它应该是mycode。doc,但这不起作用。doc字符串是模块、函数

假设mycode.py具有以下通用结构:


import bla
import bla


def function:
    bla bla


description="""My
multi-line description 
of the
code
"""


import bla
more code here

IPython中的哪个命令将打印“description=”中给出的帮助字符串


这里的所有相关问题似乎都表明它应该是mycode。doc,但这不起作用。

doc字符串是模块、函数或类中定义的第一个字符串,并且没有分配给变量/名称

my_module.py:

"""
This is the module doc-string
"""

def foo():
    """
    This is the function doc-string
    """
    pass
然后,您可以通过
属性访问文档字符串

import my_module
print(my_module.__doc__)  # This prints "This is the module doc-string"
print(my_module.foo.__doc__)  # This prints "This is the function doc-string"

文档字符串是在模块、函数或类中定义的第一个字符串,未分配给变量/名称

my_module.py:

"""
This is the module doc-string
"""

def foo():
    """
    This is the function doc-string
    """
    pass
然后,您可以通过
属性访问文档字符串

import my_module
print(my_module.__doc__)  # This prints "This is the module doc-string"
print(my_module.foo.__doc__)  # This prints "This is the function doc-string"
添加到关于放置文档字符串的位置,在交互式环境中,通常可以使用函数访问它(请注意,此函数不仅适用于模块、类和函数,还适用于关键字字符串等其他内容)

此外,在IPython中有一个
%pinfo
用于检索对象的信息,包括docstring。另一个经常使用的较短别名是
。因此,如果代码位于
my_module.py
中,则在导入后,可以使用
my_module?
访问其信息,并添加关于将文档字符串放置在何处的信息,在交互环境中,通常可以使用该功能访问它(请注意,此函数不仅适用于模块、类和函数,还适用于关键字字符串等其他对象)

此外,在IPython中有一个
%pinfo
用于检索对象的信息,包括docstring。另一个经常使用的较短别名是
。因此,如果代码位于
my_module.py
中,导入后,可以使用
my_module?
访问其信息