Python関数内のパラメータ名のリストを取得する [重複] 質問する

Python関数内のパラメータ名のリストを取得する [重複] 質問する

Python 関数内でパラメータ名のリストを取得する簡単な方法はありますか?

例えば:

def func(a,b,c):
    print magic_that_does_what_I_want()

>>> func()
['a','b','c']

ありがとう

ベストアンサー1

まあ、実際はここには必要ありませんinspect

>>> func = lambda x, y: (x, y)
>>> 
>>> func.__code__.co_argcount
2
>>> func.__code__.co_varnames
('x', 'y')
>>>
>>> def func2(x,y=3):
...  print(func2.__code__.co_varnames)
...  pass # Other things
... 
>>> func2(3,3)
('x', 'y')
>>> 
>>> func2.__defaults__
(3,)

おすすめ記事