introspecting builtin functions/methods

G

Gonçalo Rodrigues

Hi,

Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?

The following fails:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python functionTraceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function

Also:
.... print elem
....
__call__
__class__
__delattr__
__doc__
__get__
__getattribute__
__hash__
__init__
__name__
__new__
__objclass__
__reduce__
__reduce_ex__
__repr__
__setattr__
__str__

gives no clue.

TIA, with my best regards,
G. Rodrigues
 
J

Jp Calderone

Hi,

Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?

The signatures for builtins are not available via any of the normal
introspection routines. The way argument parsing works in C makes it so
that the expected arguments are not available anywhere (typically) except as
a string literal inside the function definition.

It would be pretty handy if this information was available, but I think
converting the existing code to make it available would be a herculean
effort.

Jp
 
F

Fredrik Lundh

Gonçalo Rodrigues said:
Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?

For methods/functions written in C, the signature is defined by a
string passed to an internal C function (ParseTuple). And functions
don't even have to use that function to process their arguments;
they can pull values right out of the argument tuple (or they can
use ParseTuple more than once, in order to support multiple calling
conventions).

I'd say your only hope is the doc string:
'L.append(object) -- append object to end'

</F>
 
M

Martin Franklin

Hi,

Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?

The following fails:

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function

Also:

... print elem
...
__call__
__class__
__delattr__
__doc__
__get__
__getattribute__
__hash__
__init__
__name__
__new__
__objclass__
__reduce__
__reduce_ex__
__repr__
__setattr__
__str__

gives no clue.

TIA, with my best regards,
G. Rodrigues


You mean something like:
'L.count(value) -> integer -- return number of occurrences of value'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top