number of arguments a function takes

Duncan Booth me at privacy.net
Thu Jan 29 12:08:41 EST 2004


"Elaine Jackson" <elainejackson7355 at home.com> wrote in
news:CSaSb.329909$ts4.189798 at pd7tw3no: 

> Suppose one of the arguments of a function f_1 is another function
> f_2. Can f_1 access the number of arguments taken by f_2?  (I'm
> writing a little script to automate the construction of logical
> truth-tables.)  Thanks. 

Look at the inspect module, in particular you probably want 
inspect.getargspec:

>>> import inspect
>>> def f(a,b): pass

>>> inspect.getargspec(f)
(['a', 'b'], None, None, None)
>>> help(inspect.getargspec)
Help on function getargspec in module inspect:

getargspec(func)
    Get the names and default values of a function's arguments.
    
    A tuple of four things is returned: (args, varargs, varkw, defaults).
    'args' is a list of the argument names (it may contain nested lists).
    'varargs' and 'varkw' are the names of the * and ** arguments or None.
    'defaults' is an n-tuple of the default values of the last n arguments.

>>> 



More information about the Python-list mailing list