不具合調査に使えそうなライブラリshowme
showmeはプログラムの不具合を調べるのに便利そうなデコレータのセットです
インストール
pip install showme
pycharmを使ってる場合はguiで入れても。
Preferences -> Project InterPreters -> Python InterpretersのInstallボタンから
使い方
- showme.trace
パラメータが多いfunctionにデコレータshowme.traceをつけると、どんなパラメータで呼び出されたのか出力してくれます。
import showme @showme.trace def complex_function(a, b, c, **kwargs): """ this is very complex function. """ pass complex_function(1, 'alpha','beta', debug=True)
実行結果
Calling __main__.complex_function with:
args: (1, 'alpha', 'beta')
kwargs: {'debug': True}
- showme.cputime
import showme @showme.cputime def complex_function(a, b, c, **kwargs): """ this is very complex function. """ pass complex_function(1, 'alpha','beta', debug=True)
実行結果
CPU time for __main__.complex_function:
2 function calls in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 showmetest.py:4(complex_function)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
- showme.docs
import showme @showme.docs def complex_function(a, b, c, **kwargs): """ this is very complex function. """ pass complex_function(1, 'alpha','beta', debug=True)
実行結果
Documentation for __main__.complex_function: this is very complex function.
- showme.time
import showme @showme.time def complex_function(a, b, c, **kwargs): """ this is very complex function. """ pass complex_function(1, 'alpha','beta', debug=True)
実行結果
Execution speed of __main__.complex_function: 2.86102294922e-06 seconds
