8. AND OF COURSE, YOU MIGHT WANT TO USE LOGGER
importlogging
logger=logging.getLogger(__name__)
logging.basicConfig(format='%(filename)s:%(lineno)s-%(message)s')
forjinjs:
mn=j.get('model','unknown')
js2[mn]=js2.get(mn,[])+[j]
logger.debug(js2.get(mn,[])+[j])
14. some regular python Kung Fu
_
obj.__dict__
dir(obj)
In[1]:requests.get('http://api.openweathermap.org/data/2.5/weather?id=5746545')
Out[1]:Response[200]
In[2]:response=_
21. IPDB
all the wonder of ipython plus some neat tricks:
pip install ipdb
90% use case:
with launch_ipdb_on_exception():
ipython --pdb main.py
fromipdbimportset_trace
set_trace()
29. STEPS TO PREVENT DEBUGGING
1. you have a linter, right?
2. access to all errors and tracebacks?
3. flake8 should pass for tests to pass
4. draw a line in the sand: enforce code coverage
5. add tests to prevent regressions
31. HOW MUCH IS ENOUGH?
Name Stmts Miss Cover Missing
-------------------------------------------
espm 8 0 100%
espm.espm 97 3 97% 109-112
espm.models 276 0 100%
espm.util 19 0 100%
-------------------------------------------
TOTAL 400 3 99%
----------------------------------------------------------------------
Ran32testsin0.255s
pythonsetup.pynosetests--cover-min-percentage=100
32. STELLAR RESOURCES
your friends
Stack Overflow
ipython
pudb
nose + pudb
sentry
newrelic
python memory profiler
y u no measure it
pycallgraph
ipdb post_mortem debug