如何获得像Exception这样的Python类型的签名

2024-10-03 13:26:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用inspect模块获取Exception.__init__的签名,但是在像ExceptionNone这样的Python类型上使用inspect模块失败,错误如下。你知道吗

/usr/lib/python2.7/inspect.pyc in getargspec(func)
    814         func = func.im_func
    815     if not isfunction(func):
--> 816         raise TypeError('{!r} is not a Python function'.format(func))
    817     args, varargs, varkw = getargs(func.func_code)
    818     return ArgSpec(args, varargs, varkw, func.func_defaults)

TypeError: <method-wrapper '__init__' of NoneType object at 0x8ff8d0>
is not a Python function

我想知道如何获得Python中定义类型的内置函数的签名。你知道吗


Tags: 模块none类型initis错误exceptionnot
1条回答
网友
1楼 · 发布于 2024-10-03 13:26:35

在python2.7中,inspect不适用于用C实现的函数或类,因为它们没有inspect从中获取详细信息所必需的对象属性。你知道吗

在python3.x中已经修复了这个问题

相关问题 更多 >