python debugger

18
PYTHON DEBUGGER Python Meetup Bordeaux – Node 2016-03-09 Damien Garaud / @jazzydag

Upload: damien-garaud

Post on 15-Jan-2017

163 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Python debugger

PYTHONDEBUGGERPythonMeetupBordeaux–Node

2016-03-09DamienGaraud/@jazzydag

Page 2: Python debugger

Y'AUNBUG?

Page 3: Python debugger

SCÈNEDECRIMESuspicion

Motifs(raison)

Résoudre(corriger)

Page 4: Python debugger

QUANDLorsd'untest...

oud'unrun

Ducodeàvous...

oupas

Page 5: Python debugger

Y'ALEBON,ETLEMAUVAIS

Celuiquisauteauxyeux,vousavezuneexceptionCeluiquinesevoitpas,maisvoussavezqu'yaunblème

Page 6: Python debugger

LESEXCEPTIONSSONTVOSAMIES

NameError,SyntaxErroretImportError

TypeError,ValueError,IndexError,KeyError

AttributeError,IOError,MemoryError

Page 7: Python debugger

COMMENT?

Le1erjourvientleprint()

Exceptionsoupointd'arrêt

Examinerlapiled'appels

avecunIDEouenmode"debug"

Page 8: Python debugger

EXEMPLEimportpandasaspd

defmain(fname):data=read_data(fname)result=data_processing(data)returnresult

defread_data(fname):data=pd.read_csv(fname)returndata

defdata_processing(data):returndata.query("age<=60")

if__name__=='__main__':df=main("data.csv")

Page 9: Python debugger

PILED'APPELS+------------------+|main()|||+------------------+

+------------------+|read_data()|||+------------------+

+------------------+|processing()|||+------------------+

Commeunepileenfaite

Page 10: Python debugger

LANCERPYTHONENMODEDEBUG

python-mpdbscript.py

/path/to/script.py

(Pdb)typecommandhere

:Pythondebuggeurpdb

Page 11: Python debugger

PRINCIPALESCOMMANDES

h(elp)

c(ontinue)

l(ist)

s(tep)

n(ext)

u(p)

a(rgs)

q(uit)

Page 12: Python debugger

IPYTHON

:lancepdbdansIPython

:commandemagiqueIPython

ipdb

%pdb

Page 13: Python debugger

POINTD'ARRÊTS'arrêteroùl'onsouhaite

importpdb;pdb.set_trace()

importipdb;ipdb.set_trace()

Ondoitmodifierlecode

Page 14: Python debugger

POINTD'ARRÊTDansledébuggeur

breakpoint

1. Onlancepython-mpdb

2. Importsnécessaires

3. bfuncname

Page 15: Python debugger

AVANTL'EXÉCUTIONOutilsd'analyse

pylint

pyflakes

Page 16: Python debugger

MAISÇAMARCHAITAVANT

Lasemainedernière,çamarchait,jet'assure

Gestionnairedeversionàlarescousse

gitbisect--help

Page 17: Python debugger

UNECHOSEÀRETENIRFaitesdestestsunitaires

Page 18: Python debugger

MERCI!