Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Is there an easy way to be inside a python function and get a list of the parameter names?

For example:

def func(a,b,c):

print magic_that_does_what_I_want() 

>>> func() 

['a','b','c']

Thanks

1 Answer

0 votes
by (106k points)

For getting the list of parameter names inside python function locals() returns a dictionary with local names:

def func(a,b,c):

print(locals().keys())

The above code prints the list of parameters. If you use other local variables those will be included in this list. But you could make a copy at the beginning of your function.

Related questions

Browse Categories

...