CodyKochmann
4/26/2017 - 4:50 PM

generate a list of arguments given to a function

generate a list of arguments given to a function

def function_args(fn):
    """ generates a list of the given function's arguments 
        by: Cody Kochmann """
    assert callable(fn), 'function_args needed a callable function, not {0}'.format(repr(fn))
    try: # python2 implementation
        from inspect import getargspec
        return getargspec(fn).args
    except: # python3 implementation
        from inspect import signature
        return signature(fn).parameters