help()
doesn't show the __doc__
的部分对象。
然而,docs 中的示例设置它:
>>> from functools import partial
>>> basetwo = partial(int, base=2)
>>> basetwo.__doc__ = 'Convert base 2 string to an int.'
>>> basetwo('10010')
18
为什么设置 __doc__
,如果它没有帮助?
最佳答案
为部分函数设置 __doc__
与为更大的函数设置相同:
def somefunc(somerandomarg):
"""This is a docstring
What I am doing is shorthand for __doc__ = "random docstring"
For partials, you can't do this, so you set it with __doc__"""
pass
记录任何东西总是好的,即使是部分的。
关于python - 为什么要在 Python 中设置部分对象的 __doc__?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125211/