Transcript
Page 1: Debug it-python-hack-a-thon-2011.02

DEBUG ITPython Hack-a-thon 2011.02

Page 2: Debug it-python-hack-a-thon-2011.02

お前、誰よ?

村岡友介 (MURAOKA Yusuke)

@jbking

A zoper

フリーランス

Page 3: Debug it-python-hack-a-thon-2011.02

デバッグしてますか?

Page 4: Debug it-python-hack-a-thon-2011.02

with Python - Pythonを使って何かをデバッグパケットキャプチャ, リバースエンジニアリング, 組込インタラクティブシェル(manhole), ファンクショナルテスト(Selenium client driver)

for Python - Pythonのデバッグgdb, C拡張

on Python - Python上でのデバッグprint, pdb, django-debug-toolbar

デバッグって何よ?

Page 5: Debug it-python-hack-a-thon-2011.02

with Python - Pythonを使って何かをデバッグパケットキャプチャ, リバースエンジニアリング, 組込インタラクティブシェル(manhole), ファンクショナルテスト(Selenium client driver)

for Python - Pythonのデバッグgdb, C拡張

on Python - Python上でのデバッグprint, pdbon Python - Python上でのデバッグprint, pdb, django-debug-toolbar

デバッグって何よ?

Page 6: Debug it-python-hack-a-thon-2011.02

DEBUG ITPython Hack-a-thon 2011.02

Pythonの場合

Page 7: Debug it-python-hack-a-thon-2011.02

再び質問デバッグしてますか?

Page 8: Debug it-python-hack-a-thon-2011.02

print文(関数) フレームワーク提供デバッグツール pdb その他gdb

(脳内調べ)

Page 9: Debug it-python-hack-a-thon-2011.02

今回の目標

Page 10: Debug it-python-hack-a-thon-2011.02

print文(関数) pdb フレームワーク提供デバッグツール その他gdb

Page 11: Debug it-python-hack-a-thon-2011.02

始めの一歩print文(関数)デバッグからpdbへ

Page 12: Debug it-python-hack-a-thon-2011.02

PRINTの功罪

導入がめちゃくちゃ簡単

print(“x = %d” % x)

出力された値を見るだけしかできない

Page 13: Debug it-python-hack-a-thon-2011.02

PDBを使いましょう

標準モジュール

導入がめちゃくちゃ簡単

python -mpdb demo.py

import pdb; pdb.set_trace()

実行コンテキスト上で処理を確認できる

Page 14: Debug it-python-hack-a-thon-2011.02

デモ

Page 15: Debug it-python-hack-a-thon-2011.02

次の一歩pdbからpudbへ

Page 16: Debug it-python-hack-a-thon-2011.02

PDB SUCKS

一文字の変数を確認しようとするとコマンドと解釈されてしまう(cとかnとか)

!プレフィックス付けるとOK

何をやるにもコマンドうたなきゃいけない(lとかwとか)

Page 17: Debug it-python-hack-a-thon-2011.02

PUDBを使いましょう

導入が簡単

easy_install pudb or pip install pudb

python -mpudb.run demo.py

import pudb; pudb.set_trace()

実行コンテキストを見ながら処理を確認できる

実行コンテキストのなかでシェルが使える

Page 18: Debug it-python-hack-a-thon-2011.02

デモ

Page 19: Debug it-python-hack-a-thon-2011.02

発展の話題

Page 20: Debug it-python-hack-a-thon-2011.02

フレームワークも提供してる

django-debug-toolbar

Werkzeug built-in debugger

Page 21: Debug it-python-hack-a-thon-2011.02

テストも頑張ろう

doctest

nose

pdb, pudb, doctestのサポート有り

継続ビルド(CI), バージョン管理(VCS), 環境分離(virtualenv, buildout)

Page 22: Debug it-python-hack-a-thon-2011.02

いじょっ!

Page 23: Debug it-python-hack-a-thon-2011.02

もっと使いやすいデバッグ環境あったら教えて :-)


Top Related