howto check is function capable of obtaining **kwargs?

Chris cwitts at gmail.com
Mon Jul 21 13:44:44 CEST 2008


On Jul 21, 1:20 pm, dmitrey <dmitrey.kros... at scipy.org> wrote:
> hi all,
> howto check is function capable of obtaining **kwargs?
>
> i.e. I have some funcs like
> def myfunc(a,b,c,...):...
>
> some like
> def myfunc(a,b,c,...,*args):...
>
> some like
> def myfunc(a,b,c,...,*args, **kwargs):...
>
> some like
> def myfunc(a,b,c,...,zz=zz0):...
>
> So I need to know is the given function capable of handling zz
> parameter, for example the call
> myfunc(a,b,c,...,zz=4,...)
>
> Thank you in advance, D.

>>> def f(a, b=1, c={}, *args, **kwargs):
        pass

>>> inspect.getargspec(f)
(['a', 'b', 'c'], 'args', 'kwargs', (1, {}))

>>> print inspect.getargspec.__doc__
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.

Hope that helps.
Chris



More information about the Python-list mailing list