说我有以下几点:如何打印函数头,包括名称,参数和文档字符串?
def foo(arg1, arg2, arg3 = default, *args, *kwargs*):
"""This function is really cool."""
return
我如何定义一个新的功能functionprinter(f)
,使functionprinter(f)
将打印
foo(arg1, arg2, arg3 = default, *args, *kwargs*)
This function is really cool.
或类似这种事情?我已经知道foo.__name__
和foo.__doc__
并且已经看到了inspect
模块,具体在这里:Getting method parameter names in python但似乎无法将所有内容串在一起,特别是默认参数正确打印。我正在使用Python 3.4.1。