python 如何生成如下的注释?

2016 年 2 月 24 日
 billgreen1

很多 python 的库,其文档的注释里面都包含使用案例, 比如:

"""
Helper class to unstack data / pivot with multi-level index

Parameters
----------
level : int or str, default last level
    Level to "unstack". Accepts a name for the level.

Examples
--------
>>> import pandas as pd
>>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),
...                                    ('two', 'a'), ('two', 'b')])
>>> s = pd.Series(np.arange(1.0, 5.0), index=index)
>>> s
one  a   1
     b   2
two  a   3
     b   4
dtype: float64

>>> s.unstack(level=-1)
     a   b
one  1  2
two  3  4

>>> s.unstack(level=0)
   one  two
a  1   2
b  3   4

Returns
-------
unstacked : DataFrame
"""

我想这些应该不是手动敲上去的,应该是通过某种途径自动生成的
是如何做到的?

4840 次点击
所在节点    Python
12 条回复
GPU
2016 年 2 月 24 日
手动打的。
knightdf
2016 年 2 月 24 日
手打的吧。。。
flyee
2016 年 2 月 24 日
手打 doctest
nailuoGG
2016 年 2 月 24 日
可以复制 Python 解释器下的文本输出。当然你硬是要手打的话,也行。
glasslion
2016 年 2 月 24 日
真的是手打的
wizardoz
2016 年 2 月 24 日
确实不是手动打的。
应该是复制粘贴……
BruceYuan
2016 年 2 月 24 日
哈哈,我也觉得是手打的
marshalshi
2016 年 2 月 24 日
这个是某种规范的注释结构,手打的。
gamexg
2016 年 2 月 24 日
手动打的,是一种简易单元测试。
WangYanjie
2016 年 2 月 24 日
主要靠十根手指
bbking
2016 年 2 月 24 日
感觉是 IDLE 先输入命令,然后 copy 过来的
julyclyde
2016 年 2 月 25 日

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/258776

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX