introspect c-functions?

Michael Hudson mwh at python.net
Thu Jun 6 15:33:30 CEST 2002


holger krekel <pyth at devel.trillke.net> writes:

> is there any way to introspect the *number of arguments*
> of a function implemented at c-level?

In short, no.  To the runtime almost all C functions look roughly like
python functions defined like:

def func(*args):
   pass

& so there is no way of telling what the function will do with the
arguments.  There are others -- METH_O and METH_NOARGS style C
functions -- but I don't think you can tell them apart from Python,
and they don't cover all cases.

It's a common, but hardly universal, convention to have the first line
of the docstring be something like

  func(arg1[, arg2]) -> None

so you /might/ be able to dig some info out that way -- but it's
hardly reliable.

Cheers,
M.

-- 
  ... but I'd rather not reinvent the wheel if I don't have to.  On
  the other hand, if the currently instantiated version of the wheel
  consists of a square rock covered with moss, I might as well just
  start fresh.                          -- Roy Smith, comp.lang.python



More information about the Python-list mailing list