2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでデバッグする方法

Last updated at Posted at 2017-12-06

##Pythonで簡単にデバッグする方法
下記のコードをデバッグしたい箇所に追記するだけで良い。

import pdb; pdb.set_trace()

下記sample.pyの例の様に追記する

sample.py
import pdb

pdb.set_trace()

for i in range(10):
    print(i)

sample.pyを実行するとターミナルがデバッグのコマンド待ち状態になる

-> for i in range(10):
(Pdb)

->で示されている行が次に実行される
実行後にprint(i)とかでiの中身を見ることができる

##デバッグ時のコマンド
s  次の実行可能なものが現れたら停止
n 次の行に進んだら停止
c 最後まで実行
l 周辺のコードを確認

2
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?