Appendix C. Debugging

Sometimes your Python program does not behave as you would expect. This happens in virtually every project at some point during the development process. It is a good idea to track down the cause as soon as you notice that something goes awry. This ensures that you always know that your program behaves as intended and it is built on a solid basis.

This appendix goes through the most typical ways of debugging a Python program. Since bugs are seldom really mysterious in Python, in contrast to many low-level languages such as C++, you can survive without heavy-duty debugging tools. Often a few well-placed print statements are enough to detect where the execution goes off track.

The ease of debugging in Python is based on rapid debug–evaluate iterations. Instead of assuming or trusting the documentation on how a PyS60 API function or a Python language construct behaves, you can try it in practice. Thus, the first step in successful debugging is to make sure that you can update your code on your phone with a minimal number of steps, as described in Chapter 2 and Section 10.3.

Be prepared to make lots of small changes to your code quickly. If modifying the code is a frustrating and time-consuming activity for you, check if you can streamline your development process. You should be able to update the program on your phone with two or three clicks from your PC.

Once you are fluent in updating the code, you should become accustomed to developing your code in short ...

Get Mobile Python: Rapid Prototyping of Applications on the Mobile Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.