2012-06-06 32 views
7

如何獲取內置方法的簽名? 例:字典()得到(K)獲取內置方法簽名 - Python

>> 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) 
+0

[如何獲取內建Python類構造函數的參數列表?](http://stackoverflow.com/questions/7628081/how-to-get-arguments-list-of-a-built -in-python-class-constructor) – ChristopheD

+0

相關:http://bugs.python.org/issue1748064總結:目前你不能(在CPython中)。 – ChristopheD

回答

4

我不認爲這是有可能在python的內置函數在C中實現。有關更多詳細信息,請參見this錯誤討論。