如何使PyCharm中的文档字符串与Jupyter Notebook中的docstring一样有用?

时间:2016-08-19 19:48:05

标签: python pycharm jupyter-notebook

Jupyter笔记本 键入命令和“()”并按下Jupyter笔记本中的Shift + Tab的文档(一个很好的文档字符串,其中解释了所有参数并显示了示例): enter image description here

PyCharm 输入命令并在PyCharm中按Ctrl + Q时的文档(仅显示带有推断变量类型的自动生成的文档字符串): enter image description here

修改 这个问题涉及对外部(例如matplotlibs或numpy)文档装饰器的评估,而不是如何编写自己漂亮的文档字符串。

1 个答案:

答案 0 :(得分:1)

你的意思是“如何编写我自己的代码的文档字符串......”?

因为,如果使用Sphinx/reStructuredText语法,则可以获得精美的文档。

这是一个基本的例子:

def axhline_demo(y=0, xmin=0, xmax=1, hold=None, **kwargs):
    """
    Add a horizontal line across the axis.

    Parameters
    ----------

    :param y: scalar, optional, default: 0

        y position in data coordinates of the horizontal line.

    :param xmin: scalar, optional, default: 0

        etc.

    :param xmax: more documentation...
    :param hold:
    :param kwargs:
    :return:
    """

你会得到:

enter image description here

使用菜单查看 => 快速文档