names of parameters as string

Jean Brouwers JBrouwersAtProphICyDotCom at no.spam.net
Fri Oct 29 23:59:45 EDT 2004



Take a look at the getargspec() function in the inspect module.  It
returns a 4-tuple and the first item of that tuple is a list of the
parameter names of a function or method.

<pre>
  import inspect
  def foo(p1, p2):
    pass
  print inspect.getargspec(foo)

results in:

  (['p1', 'p2'], None, None, None)

</pre>

The second item is the name of the *args argument, the third is the
name of the **kwds argument and the last item is a tuple of the values
of the kwds args.

More details in

<http://docs.python.org/lib/inspect-classes-functions.html>

and on page 381 of the (outstanding, IMO) book "Python in a Nutshell",
1st edition.


/Jean Brouwers
 ProphICy Semiconductor, Inc.


>  >>> def foo( foo_param1, foo_param2):


In article <mailman.5663.1099065452.5135.python-list at python.org>,
andrea valle <andrea.valle at unito.it> wrote:

> Hi to all,
> I'd like to access the parameter list of a function (or better of a 
> method) in order to generate GUI elements.
> That is.
> If I have this:
> 
>  >>> def foo( foo_param1, foo_param2):
>     print foo_param
> 
> I'd like to have something like:
> 
>  >>> print foo.param_list
>  >>> 'foo_param1', 'foo_param2'
> 
> My idea is to use the foo_params strings in Tkinter as text for Label 
> and as variables for Entries.
> 
> What have I to do?
> 
> Thanks a lot as usual
> 
> Best
> 
> -a-
> 
> 
> _____________________________________________________________________
> For your security, this mail has been scanned and protected by Inflex



More information about the Python-list mailing list