[英]How to override original signature of a function in python
假設我有以下 function:
def person(*args, **kwargs):
'''
person(name, age, parents=2)
this is a docstring.
'''
如果我執行help(person)
我會得到
person(*args, **kwargs)
person(name, age, children=5)
this is a docstring.
但相反,我想看到:
person(name, age, children=5)
this is a docstring.
您可以簡單地覆蓋.__doc__
屬性:
def a():
"""orig docstring"""
pass
help(a)
a.__doc__ = """modified docstring"""
help(a)
你總是可以使用文檔字符串,像這樣:
def function(...):
"""
This function does this and that. The parameters are the following:
param1 = ...
param2 = ...
...
"""
# code
然后你可以簡單地調用。 doc方法,它打印出文檔字符串。 它是這樣工作的:
print.__doc__
或者為了更好的可讀性:
import pprint
pprint.pprint(pprint.__doc__, indent=4)
Pprint 是漂亮的打印。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.