>>> def test(arg1, arg2, arg3=None): pass
>>> test.func_code.co_varnames
('arg1', 'arg2, 'arg3')
What I want is something like:
{'args': ('arg1', 'arg2'), 'kwargs': {'arg3': None}}
Is there a way to achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
inspect.getargspec()to get the arguments a function expects.As you can see the
keywordsattribute isNoneas any argument can be passed as a kwarg; it would contain the name of the**kwargsargument if one existed.To get a dict mapping the argument names to default values you can use this code with
asbeing the ArgSpec returned byinspect.getargspec():