Search code examples
pythonfunctionintrospection

Get Keyword Arguments for Function, Python


def thefunction(a=1,b=2,c=3):
    pass

print allkeywordsof(thefunction) #allkeywordsof doesnt exist

which would give [a,b,c]

Is there a function like allkeywordsof?

I cant change anything inside, thefunction


Solution

  • Do you want something like this:

    >>> def func(x,y,z,a=1,b=2,c=3):
        pass
    
    >>> func.func_code.co_varnames[-len(func.func_defaults):]
    ('a', 'b', 'c')