Possible Duplicate:
Getting list of parameters inside python function
E.g. supposes I have
def foo(a, b='B'): return
How can I ask foo to tell me that it has required parameter ‘a’, and parameter ‘b’, which has ‘B’ as it’s default value?
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.
Use
inspect.getargspec.It may appear to be unclear which argument the default is for, but since non-default arguments can’t follow default arguments, the default has to be for the 2nd argument.
Edit: The linked duplicate is good, an answer there shows you can get the same info without
inspect, usingfunc.func_code.co_varnamesandfunc.func_defaultsorfunc.__defaults__.