• 8 hours
  • Easy

Free online content available in this course.



Got it!

Last updated on 3/28/24

Use Linters to Keep Your Code Tidy

If I make a typo or a grammar mistake while writing this paragraph, the text editor highlights it so I can correct it. It doesn’t find all my mistakes. I could write nonsense about how snakes invented the Python language, and it wouldn’t notice! 🐍  But at least it ensures that I’m using correct English.

Wouldn’t it be useful if something like that existed for the Python language?

There is! It’s called a linter and finds places in your code where you aren’t conforming to PEP 8. Then it’s up to you to fix those issues (or in some instances, you might be breaking PEP 8 intentionally, in which case you would ignore some of the linter’s output).

It doesn’t check whether your Python code will run correctly or as expected. It’s a spell checker that doesn’t verify your facts. But it will prevent you from running into the problems we’ve been looking at in the previous three chapters.

Using a Linter

Some editors have linters built in. There are also free online ones.

They’re super easy to use, so let’s take a look!

Try It Yourself!

Download this file - it’s the same one that you saw in the video - and run it through a linter. There will be lots of errors! The Python code is correct, but it doesn’t respect PEP 8 yet.

Fix all the errors you can find, and then keep running it through the linter until it no longer finds any errors.

If you get stuck, you can compare it to the solution.

Let’s Recap!

  • A linter is an automated tool that warns you when your code is not PEP 8-compliant.

  • Linters don’t find all your programming mistakes but only the main style recommendations of PEP 8.

Test your understanding of PEP 8 with the following quiz! In the next part of the course, you’ll learn how using design patterns to structure your programs can keep them maintainable.

Ever considered an OpenClassrooms diploma?
  • Up to 100% of your training program funded
  • Flexible start date
  • Career-focused projects
  • Individual mentoring
Find the training program and funding option that suits you best
Example of certificate of achievement
Example of certificate of achievement