Given that a function a_method has been defined like
def a_method(arg1, arg2): pass
Starting from a_method itself, how can I get the argument names – for example, as a tuple of strings, like ("arg1", "arg2")?
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.
Take a look at the
inspectmodule – this will do the inspection of the various code object properties for you.The other results are the name of the *args and **kwargs variables, and the defaults provided. ie.
Note that some callables may not be introspectable in certain implementations of Python. For Example, in CPython, some built-in functions defined in C provide no metadata about their arguments. As a result, you will get a
ValueErrorif you useinspect.getfullargspec()on a built-in function.Since Python 3.3, you can use
inspect.signature()to see the call signature of a callable object: