• 8 heures
  • Moyenne

Ce cours est visible gratuitement en ligne.

course.header.alt.is_video

course.header.alt.is_certifying

J'ai tout compris !

Mis à jour le 30/08/2022

Set Up a Debugging Environment

What’s a Debugger?

The best programmers always use the best tools when writing code. But, as you know, rather than simply writing your code in a text editor, it’s better to use a special-purpose software—an integrated development environment, or IDE.

You’re probably already familiar with some IDEs such as PyCharm or Visual Studio Code. They have features like syntax highlighting, which help you read and understand your code more easily by displaying different parts in different colors. Using autocompletion, IDEs can also offer suggestions as you write, making your job easier and saving time. 

But what’s even better is that IDEs can turn into a debugger. They have some specially developed tools for finding and eliminating bugs, including two essential ones: the linter and the debugger. The linter analyzes code before it runs, and the debugger analyzes it while it’s running, as you can see in the chapter “Use Linters to Keep Your Code Tidy” from the Write Maintainable Python Code course. 

Python also has modules to help with debugging. We’re going to use the pdb and logging modules. Since they are part of the standard Python library, you don’t need to install them. 

You can check that pdb and logging are working properly by writing this in your program:

import pdb
import logging

If nothing happens, it means everything’s working as it should. You’ll learn to use these in another chapter, but first, let’s check that the environment is installed correctly and then move on to the next point.

Install Your IDE (If You Haven’t Already!)

Which IDE should you choose? I recommend using one of the most popular ones: PyCharm or Visual Studio Code. Here are two OpenClassrooms courses that will help you install them and understand their basic settings:

Next, we’ll set them up to debug our web project and software.

Over to You!

It’s time to dive into our case study! Throughout the course, we will debug a project allowing users to play rock-paper-scissors against an AI. 🤖 There is a tkinter version of the project and two web versions (coded using Flask and Django). Here’s a demonstration of how it should work with no bugs:

Just get used to how it works for the moment—we’ll start debugging it in the next part.

You can see the projects in the GitHub repository here:

Let’s Recap!

  • An IDE program allows you to write, run, and debug code. 

  • The debugging features of an IDE help you detect and eliminate bugs.

  • Pdb and logging are useful modules for debugging in Python.

Now you have everything to start work; it’s time to get into the nitty-gritty of debugging! But first, test your new knowledge with a quiz. See you in the next part!

Exemple de certificat de réussite
Exemple de certificat de réussite