getting number of arguments of builtin/C func

Chris Liechti cliechti at gmx.net
Wed Mar 6 21:09:22 EST 2002


i know these two:
>>>numArgs = func.func_code.co_argcount
>>>func.func_code.co_varnames[:numArgs]

>>>apply(inspect.formatargspec, inspect.getargspec(f))

both only work for python functions, but i would like to know the 
number of arguments a function takes regardles if its a type, builtin 
or python func.

any ideas appart from calling with zero args and parsing the 
exception string (scanning: "TypeError: f() takes exactly 2 arguments 
(0 given)") ...

chris


(i'm playing around with an RPN calculator and would like to take as 
much arguments from the stack as needed for an unknown function. i 
have a table of known functions but that's not so flexible)

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list