python debugger
TRANSCRIPT
PYTHONDEBUGGERPythonMeetupBordeaux–Node
2016-03-09DamienGaraud/@jazzydag
Y'AUNBUG?
SCÈNEDECRIMESuspicion
Où
Motifs(raison)
Résoudre(corriger)
QUANDLorsd'untest...
oud'unrun
Ducodeàvous...
oupas
Y'ALEBON,ETLEMAUVAIS
Celuiquisauteauxyeux,vousavezuneexceptionCeluiquinesevoitpas,maisvoussavezqu'yaunblème
LESEXCEPTIONSSONTVOSAMIES
NameError,SyntaxErroretImportError
TypeError,ValueError,IndexError,KeyError
AttributeError,IOError,MemoryError
COMMENT?
Le1erjourvientleprint()
Exceptionsoupointd'arrêt
Examinerlapiled'appels
avecunIDEouenmode"debug"
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")
PILED'APPELS+------------------+|main()|||+------------------+
+------------------+|read_data()|||+------------------+
+------------------+|processing()|||+------------------+
Commeunepileenfaite
LANCERPYTHONENMODEDEBUG
python-mpdbscript.py
/path/to/script.py
(Pdb)typecommandhere
:Pythondebuggeurpdb
PRINCIPALESCOMMANDES
h(elp)
c(ontinue)
l(ist)
s(tep)
n(ext)
u(p)
a(rgs)
q(uit)
IPYTHON
:lancepdbdansIPython
:commandemagiqueIPython
ipdb
%pdb
POINTD'ARRÊTS'arrêteroùl'onsouhaite
importpdb;pdb.set_trace()
importipdb;ipdb.set_trace()
Ondoitmodifierlecode
POINTD'ARRÊTDansledébuggeur
breakpoint
1. Onlancepython-mpdb
2. Importsnécessaires
3. bfuncname
AVANTL'EXÉCUTIONOutilsd'analyse
pylint
pyflakes
MAISÇAMARCHAITAVANT
Lasemainedernière,çamarchait,jet'assure
Gestionnairedeversionàlarescousse
gitbisect--help
UNECHOSEÀRETENIRFaitesdestestsunitaires
MERCI!