例如,我导入了Tkinter,并想检查Tkinter.Frame.__init__
参数列表是如何定义的,可能还有函数内部的内容。我期待Tkinter.Frame.__init__.__doc__
之类的东西。
(我没有使用Python IDE,因此不会弹出参数列表)
答案 0 :(得分:3)
我建议您查看inspect.getargspec
和inspect.getsource
:
>>> import inspect
>>> inspect.getargspec(inspect.getargspec)
ArgSpec(args=['func'], varargs=None, keywords=None, defaults=None)
>>> print inspect.getsource(inspect.getsource)
def getsource(object):
"""Return the text of the source code for an object.
The argument may be a module, class, method, function, traceback, frame,
or code object. The source code is returned as a single string. An
IOError is raised if the source code cannot be retrieved."""
lines, lnum = getsourcelines(object)
return string.join(lines, '')