获取内置方法签名 - Python [英] Get built in method signature - Python

查看:33
本文介绍了获取内置方法签名 - Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取内置方法的签名?示例:dict().get(k)

How do I get the signature of built in methods? Example: dict().get(k)

>> a = dict().get
>> a
<built-in method get of dict object at 0x1003aafd0>
>> a.__doc__
'D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.'
>> import inspect
>> inspect.getargspec(a)
TypeError: <built-in method get of dict object at 0x100377250> is not a Python function

我想看到这样的结果

>> a.some_function()
('key', 'default'=None)

推荐答案

我不认为这对于用 C 实现的 Python 中的内置函数是可能的.参见 this 错误讨论以获取更多详细信息.

I don't think this is possible for the built-in functions in python that are implemented in C. See this bug discussion for further details.

这篇关于获取内置方法签名 - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆