Knowing the signature of a function

Gerald Klix Gerald.Klix at klix.ch
Wed Jun 8 14:33:13 CEST 2005


Use the inspect module like:

 >>> def tf( a, b, c, *arguments, **keywordArguments ):
...  print "tf"
...
 >>> import inspect
 >>> inspect.getargspec( tf )
(['a', 'b', 'c'], 'arguments', 'keywordArguments', None)
 >>>

Xavier Décoret schrieb:
> Hello,
> 
> I have the following code:
> 
> def foo(x,y):
> 	pass
> 
> How can I query the function object foo to know the number of parameters 
> it expects.  I can find it is a function using callable(f), I can find 
> some information (listed by dir(foo)) such as the name of the 
> function,etc.. but nowhere I can find the number of arguments.
> 
> I would like to know wether the function expects one or zero arguments.

-- 
GPG-Key: http://keyserver.veridis.com:11371/search?q=0xA140D634




More information about the Python-list mailing list