python pdbデバッグおよびsublime 3ショートカット設定

2722 ワード

python pdbデバッグおよびsublime 3ショートカット設定
pdbデバッグ
gdbに詳しいなら、pdbは使いやすいです.よく使用されるデバッグコマンドをdemoですばやく理解します.
def test(a):
    while True:
        if a > 10:
            break
        a += 1
    return a

if __name__ == '__main__':
    test(1)
  • python -m pdb test.pyデバッグ環境
  • b test test testはtest関数にブレークポイントを設定し、ブレークポイント番号は1
  • である.
    (Pdb) b test
    Breakpoint 1 at f:\python\pdb\test.py:1
  • b 2は、2行目にブレークポイントを設ける、ブレークポイント番号は2
  • である.
    (Pdb) b 2
    Breakpoint 2 at f:\python\pdb\test.py:2
  • condition 2 a=7 2番ブレークポイントに条件a=7
  • を設定
  • bは、すべてのブレークポイント情報
  • を表示する.
    (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
  • cl 1は1番のブレークポイントを除去し、clだけがすべてのブレークポイント
  • を削除する.
    (Pdb) cl 1
    Deleted breakpoint 1
  • n単一ステップ追跡、関数
  • に入らない
    (Pdb) n 
    > f:\python\pdb\test.py(8)()
    -> if __name__ == '__main__':
    (Pdb) n 
    > f:\python\pdb\test.py(9)()
    -> test(1)
  • s単一ステップ追跡、関数
  • (Pdb) s
    --Call--
    > f:\python\pdb\test.py(1)test()
    -> def test(a):
  • cは、a=7条件のブレークポイントで
  • を停止して運転を継続する.
  • pの場合、印刷aの値は7
  • となる.
    (Pdb) c 
    > f:\python\pdb\test.py(2)test()
    -> while True:
    (Pdb) p a
    7
  • aは、関数パラメータ
  • を印刷する.
    (Pdb) a 
    a = 7
  • l実行コード
  • を表示
    (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]
  • quit終了
  • sublime設定
    sublimeは、ショートカットキーF 5を実行に設定し、Ctrl+F 5をデバッグします.pythonデバッグに便利になります.
  • Package ControlでSublimeREPL(Read-Eval-print-Loop)
  • をダウンロード
  • Preferneces->KeyBingdings-User設定
  • [
      {
        "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"
        }
      }
    ]