def describe_arguments(func):
    """
    Analyze a function's signature and return a data structure suitable for
    passing in as arguments to an argparse parser's add_argument() method."""

    argspec = inspect.getargspec(func)
    # we should probably raise an exception somewhere if func includes **kwargs
    if argspec.defaults:
        positional_args = argspec.args[:-len(argspec.defaults)]
        keyword_names = argspec.args[-len(argspec.defaults):]
        for arg, default in zip(keyword_names, argspec.defaults):
            yield ('--{}'.format(arg),), {'default': default}
    else:
        positional_args = argspec.args

    for arg in positional_args:
        yield (arg,), {}
    if argspec.varargs:
        yield (argspec.varargs,), {'nargs': '*'}
def describe_arguments ( func ) : argspec = inspect . getargspec ( func ) if argspec . defaults : positional_args = argspec . args [ : - len ( argspec . defaults ) ] keyword_names = argspec . args [ - len ( argspec . defaults ) : ] for arg , default in zip ( keyword_names , argspec . defaults ) : yield ( '--{}' . format ( arg ) , ) , { 'default' : default } else : positional_args = argspec . args for arg in positional_args : yield ( arg , ) , { } if argspec . varargs : yield ( argspec . varargs , ) , { 'nargs' : '*' }
Analyze a function's signature and return a data structure suitable for
    passing in as arguments to an argparse parser's add_argument() method.