Summary

In this chapter, we learned about different debugging techniques with Python. We started with the simple print statement and followed it with simple tricks to debug a Python program such as using the continue statement in a loop, strategically placing the sys.exit calls between code blocks, and so on.

We then looked at debugging techniques in some detail, especially on mocking and randomizing data. Techniques such as caching in files and in-memory databases such as Redis were discussed with examples.

An example using Python schematics library showed generating random data for a hypothetical application in the healthcare domain.

The next section was about logging and using it as a debugging technique. We discussed simple logging using the logging module, advanced logging using the logger object, and wrapped up the discussion by creating a logger wrapper with its custom formatting for logging the time taken inside functions. We also studied an example of writing to syslog.

The end of the chapter was devoted to a discussion on debugging tools. You learned the basic commands of pdb, the Python debugger, and took a quick look at similar tools that provide a better experience, namely, iPdb and Pdb++. We ended the chapter with a brief discussion on tracing tools such as lptrace and the ubiquitous strace program on Linux.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.187