可能性の重複:Pythonの関数を考える
How to find out the arity of a method in PythonPythonの関数のパラメータ数
、どのように私はプログラム的にそれが取るパラメータの数を決定するのですか?
可能性の重複:Pythonの関数を考える
How to find out the arity of a method in PythonPythonの関数のパラメータ数
、どのように私はプログラム的にそれが取るパラメータの数を決定するのですか?
が検査http://docs.python.org/library/inspect.html#inspect.getargspecがinspect.getargspec(func)コマンドを見てみましょう。この場合
>>> def testFunc(arg1, arg2, arg3, additional='test'):
... print arg1
...
>>> import inspect
>>> inspect.getargspec(testFunc)
ArgSpec(args=['arg1', 'arg2', 'arg3', 'additional'], varargs=None, keywords=None, defaults=('test',))
>>>
機能の外から、あなたは)(inspect.getargspec使用することができます。
であなたの友達です。それはあなたにタプルを与えます、最初の要素は必要なパラメータのリストです。
可能な複製:http://stackoverflow.com/questions/990016/how-to-find-out-the-arity-of-a-method-in-python、http://stackoverflow.com/questions/ 3913963/python-arguments-of-python-function/3915056#3915056 – mouad