我想弄清楚从模块中检索到的方法的参数。 我发现一个带有便利功能的inspect
模块,getargspec
。 它适用于我定义的功能,但不适用于导入模块的功能。Python inspect.getargspec与内置函数
import math, inspect
def foobar(a,b=11): pass
inspect.getargspec(foobar) # this works
inspect.getargspec(math.sin) # this doesn't
我会得到这样的错误:
File "C:\...\Python 2.5\Lib\inspect.py", line 743, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function
是inspect.getargspec
仅用于本地功能设计还是我做错了什么?
是的,它是这样设计的,请参阅http://bugs.python.org/issue1748064 – georg 2012-07-05 11:16:30