Number of args in a function

Mark Aristotle_00 at yahoo.com
Tue Oct 16 16:39:25 EDT 2001


Hello all,

I would like to find either a built-in function or a method of making
my own function to answer the following question:

Given a function f, how many arguments does it take?  I know there is
some subtlety here but I'll be happy with just the number of formal
arguments.

So, if I had nargs(abs) I would get a "1" and if I had nargs(add) I
would get a "2".  (assuming I had imported the functional versions
from "operator")

The closest thing I've been able to come up with is parsing the
TypeException error that is raised when you call a function with the
wrong number of arguments.

Thanks all.

Regards, 
Mark



More information about the Python-list mailing list