Pythonに任せてみませんか?inspection
モジュールは関数のソースを出力できると思うので、モジュールをインポートし、関数を選択して検査するだけです。ちょっとまって。あなたのための解決策を打ち破る...
わかった。inspect.getsource
インタラクティブに定義されたものに対して関数が機能しないことがわかりました。
>>> def test(f):
... print 'arg:', f
...
>>> test(1)
arg: 1
>>> inspect.getsource(test)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\inspect.py", line 699, in getsource
lines, lnum = getsourcelines(object)
File "C:\Python27\lib\inspect.py", line 688, in getsourcelines
lines, lnum = findsource(object)
File "C:\Python27\lib\inspect.py", line 529, in findsource
raise IOError('source code not available')
IOError: source code not available
>>>
ただし、ユースケースでは機能します。ディスクに保存されたモジュールの場合。たとえば、私のtest.py
ファイルを見てください:
def test(f):
print 'arg:', f
def other(f):
print 'other:', f
そして、このインタラクティブなセッションと比較してください:
>>> import inspect
>>> import test
>>> inspect.getsource(test.test)
"def test(f):\n print 'arg:', f\n"
>>> inspect.getsource(test.other)
"def other(f):\n print 'other:', f\n"
>>>
だから... Pythonソースファイルの名前と関数/オブジェクト名を引数として受け入れる簡単なpythonスクリプトを書く必要があります。次に、モジュールをインポートして関数を検査し、それを STDOUT に出力する必要があります。