getting argument names from a function

Travis Oliphant oliphant.travis at ieee.org
Wed Jul 11 00:59:55 CEST 2001


> On Tue, 10 Jul 2001, dan wrote:
> 
> > def aFunction(arg1, arg2):
> >    print arg1, arg2
> >
> > is there a way I can get to the arguments of aFunction (i.e. 'arg1' and
> > 'arg2')?
> >
> > I've tried dir(..) on the function object and subsequent object and
> > can't find what I'm looking for. Is it possible to do what I want?
> >

In Python 2.1 the inspect module provides easy access to the introspection 
facilities of Python.  

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

will return

aFunction(arg1, arg2)

I just found this facility myself and am using it to add a simple help 
command to SciPy (www.scipy.org)



-- 
Travis Oliphant, Ph.D
Assistant Professor
Electrical and Computer Engineering
Brigham Young University
Provo, UT 84602
(801) 378-3108
oliphant.travis at ieee.org



More information about the Python-list mailing list