【问题标题】:What is the use of PyCharm's docstring template? How do I use it effectively?PyCharm 的 docstring 模板有什么用?我如何有效地使用它?
【发布时间】:2015-06-01 07:47:20
【问题描述】:

PyCharm,当我开始输入文档字符串时,Python IDE 会为文档字符串生成一个模板。这是为一个简单函数生成的模板。

def add_them(x, y):
    """

    :param x: 
    :param y: 
    :return:
    """
    z = x + y
    return z

我没有发现它与 Python 的官方文档字符串 conventions 相似。

这个模板对 readthedocs 这样的文档生成器有什么用吗?

人们如何有效地使用?

填充模板的正确方法是什么?

谢谢。

【问题讨论】:

    标签: python coding-style documentation pycharm docstring


    【解决方案1】:

    我们将它与 sphinx-apidoc 一起使用来生成我们的 HTML 和 PDF 文档。

    这是我如何使用文档字符串的示例:

    def add_pdr(process, userid, log):
        """ Create and perform the target account operation PDR
    
        If the function/method is complex, I'd put a short one-line
        summary in the first line above, and a more detailed explanation
        here.
    
        :param dict process: dict of process details
        :param str userid: userid to perform actions on
        :param obj log: log object to perform logging to
    
        :raises KeyError: if the userid doesn't exist
        :raises APIError: if process dict is invalid
    
        :return: True on success, False upon failure
    
        """
    

    【讨论】:

    • 你会用exception 的例子更新答案吗?
    • 添加异常/引发示例
    • 参数类型是用户输入的还是自动生成的?
    • 很抱歉这个问题,但我非常喜欢这个“模板”。但是,您是否建议同时使用:rtype 来指定返回变量的类型?
    • @RayKoopa 是的。我们也经常使用:rtype
    猜你喜欢
    • 2018-05-06
    • 1970-01-01
    • 2018-07-08
    • 2013-04-07
    • 1970-01-01
    • 2011-10-09
    • 2015-12-26
    • 2011-02-13
    • 2016-10-17
    相关资源
    最近更新 更多