PyCharm 2017.1 Help

Debugging Python Code

In this section:

What these tutorials are about

In this tutorial, we’re going to debug the Python code. With the example code provided below you can try all of the features mentioned in these tutorials.

Learning all the debugging features and capabilities is out of scope. With this tutorial you’ll learn the most important ways to debug your code by example.

Before you start

Make sure that:

  • You are working with PyCharm. If you still do not have PyCharm, download it from this page . To install PyCharm, follow the instructions, depending on your platform.

    This tutorial has been created with PyCharm version 2017.1.

  • You have created a project.

Preparing an example

Copy the following code into a file in your project (though it is recommended to type this code manually):

import math class Solver: def demo(self, a, b, c): d = b ** 2 - 4 * a * c if d > 0: disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 elif d == 0: return -b / (2 * a) else: return "This equation has no roots" if __name__ == '__main__': solver = Solver() while True: a = int(input("a: ")) b = int(input("b: ")) c = int(input("c: ")) result = solver.demo(a, b, c) print(result)

Placing breakpoints

To place breakpoints, just click the left gutter next to the line you want your application to suspend at.

Refer to section Breakpoints for details.

//todo add image

Starting the debugging session

OK now, as we've added breakpoints, everything is ready for debugging.

Last modified: 26 July 2017