introspection and functions
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Aug 20 15:04:54 EDT 2007
yagyala a écrit :
> Hi. I would like to be able to tell, at run time, how many parameters
> a function requires. Ideally I would like to be able to tell which are
> optional as well. I've tried looking at the functions attributes, but
> haven't found one that helps in this. How can I do this?
>>> def myfunc(arg1, arg2, arg3='toto', *args, **kw): pass
...
>>> import inspect
>>> inspect.getargspec(myfunc)
(['arg1', 'arg2', 'arg3'], 'args', 'kw', ('toto',))
HTH
More information about the Python-list
mailing list