首页 文章

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

提问于
浏览
4

Jupyter Notebook 在输入命令和"()"并按下Jupyter笔记本中的Shift选项卡时的文档(一个很好的文档字符串,其中解释了所有参数并显示了示例):
enter image description here

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

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

1 回答

  • 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

    使用菜单 View => Quick Documentation .

相关问题