最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Grouping function parameters with sphinx - Stack Overflow

programmeradmin1浏览0评论

I want to group the parameters of a function so that, instead of

myfunc(from, until, col_color, col_taste)
    Parameters:   · from First date of the period to be selected.
                  · until Last date of the period to be selected.
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

I want to have

myfunc(from, until, col_color, col_taste)
    Selection parameters:
                  · from First date of the period to be selected.
                  · until Last date of the period to be selected.

    Content parameters:
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

Is there a means to do this?

I tried to write the doc-string for the function as follows:

def myfunc(from, until, col_color, col_taste)
    """
    Gets data from the desires period and returns them as a dataframe.

    Selection parameters:
    :param from: First date of the period to be selected.
    :param until: Last date of the period to be selected.

    Content parameters:
    :param col_color: Whether to include the color column in the
                    output.
    :param col_taste: Whether to include the taste column in the
                    output.

But then, he list of all parameters are printed twice, one below the "Selection parameters" text and another one after the "Content parameters" text.

I want to group the parameters of a function so that, instead of

myfunc(from, until, col_color, col_taste)
    Parameters:   · from First date of the period to be selected.
                  · until Last date of the period to be selected.
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

I want to have

myfunc(from, until, col_color, col_taste)
    Selection parameters:
                  · from First date of the period to be selected.
                  · until Last date of the period to be selected.

    Content parameters:
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

Is there a means to do this?

I tried to write the doc-string for the function as follows:

def myfunc(from, until, col_color, col_taste)
    """
    Gets data from the desires period and returns them as a dataframe.

    Selection parameters:
    :param from: First date of the period to be selected.
    :param until: Last date of the period to be selected.

    Content parameters:
    :param col_color: Whether to include the color column in the
                    output.
    :param col_taste: Whether to include the taste column in the
                    output.

But then, he list of all parameters are printed twice, one below the "Selection parameters" text and another one after the "Content parameters" text.

Share Improve this question asked Feb 4 at 14:18 Antonio SerranoAntonio Serrano 5053 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I now get the desired results. The reason for the parameters being printed twice was not related to the way I grouped them. So, it is ok to do it in the way I have done.

The reason for the parameters being printed twice was that I used two extensions, in the source/conf.py file that serve the same purpose: to write the default values of the function parameters in the output html. The two extensions are: sphinx_autodoc_typehints and sphinxcontrib.default_values. I eliminated the last one, because the former aims to accomplish more additional tasks.

发布评论

评论列表(0)

  1. 暂无评论