python pdbデバッグおよびsublime 3ショートカット設定
2722 ワード
python pdbデバッグおよびsublime 3ショートカット設定
pdbデバッグ
gdbに詳しいなら、pdbは使いやすいです.よく使用されるデバッグコマンドをdemoですばやく理解します. python -m pdb test.pyデバッグ環境 へ b test test testはtest関数にブレークポイントを設定し、ブレークポイント番号は1 である. b 2は、2行目にブレークポイントを設ける、ブレークポイント番号は2 である. condition 2 a=7 2番ブレークポイントに条件a=7 を設定 bは、すべてのブレークポイント情報 を表示する. cl 1は1番のブレークポイントを除去し、clだけがすべてのブレークポイント を削除する. n単一ステップ追跡、関数 に入らない s単一ステップ追跡、関数 へ cは、a=7条件のブレークポイントで を停止して運転を継続する. pの場合、印刷aの値は7 となる. aは、関数パラメータ を印刷する. l実行コード を表示 quit終了 sublime設定
sublimeは、ショートカットキーF 5を実行に設定し、Ctrl+F 5をデバッグします.pythonデバッグに便利になります. Package ControlでSublimeREPL(Read-Eval-print-Loop) をダウンロード Preferneces->KeyBingdings-User設定
pdbデバッグ
gdbに詳しいなら、pdbは使いやすいです.よく使用されるデバッグコマンドをdemoですばやく理解します.
def test(a):
while True:
if a > 10:
break
a += 1
return a
if __name__ == '__main__':
test(1)
(Pdb) b test
Breakpoint 1 at f:\python\pdb\test.py:1
(Pdb) b 2
Breakpoint 2 at f:\python\pdb\test.py:2
(Pdb) b
Num Type Disp Enb Where
1 breakpoint keep yes at f:\python\pdb\test.py:1
2 breakpoint keep yes at f:\python\pdb\test.py:2
stop only if a==7
(Pdb) cl 1
Deleted breakpoint 1
(Pdb) n
> f:\python\pdb\test.py(8)()
-> if __name__ == '__main__':
(Pdb) n
> f:\python\pdb\test.py(9)()
-> test(1)
(Pdb) s
--Call--
> f:\python\pdb\test.py(1)test()
-> def test(a):
(Pdb) c
> f:\python\pdb\test.py(2)test()
-> while True:
(Pdb) p a
7
(Pdb) a
a = 7
(Pdb) l
1 def test(a):
2 B-> while True:
3 if a > 10:
4 break
5 a += 1
6 return a
7 if __name__ == '__main__':
8 test(1)
[EOF]
sublimeは、ショートカットキーF 5を実行に設定し、Ctrl+F 5をデバッグします.pythonデバッグに便利になります.
[
{
"keys": [
"f5"
],
"caption": "SublimeREPL: Python - RUN current file",
"command": "run_existing_window_command",
"args": {
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
},
{
"keys": [
"ctrl+f5"
],
"caption": "SublimeREPL: Python - PDB current file",
"command": "run_existing_window_command",
"args":
{
"id": "repl_python_pdb",
"file": "config/Python/Main.sublime-menu"
}
}
]