在python中,如何检查导入模块方法的函数形式

时间:2011-12-19 16:21:29

标签: python

例如,我导入了Tkinter,并想检查Tkinter.Frame.__init__参数列表是如何定义的,可能还有函数内部的内容。我期待Tkinter.Frame.__init__.__doc__之类的东西。

(我没有使用Python IDE,因此不会弹出参数列表)

1 个答案:

答案 0 :(得分:3)

我建议您查看inspect.getargspecinspect.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, '')