This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 9: The PEP 8 style guide

PyCodeStyle

face Josiah Wang

You can check whether your code conforms to PEP 8 with the Python command line utility pycodestyle.

You can install this using pip install pycodestyle.

Prepare a script (say test.py) that does not conform to PEP 8 (for example using two spaces for indentation). Here is an example below.

guess = 5
if guess > 5:
  print("Too large")
  print("Try again")
else:
  print("Ok")

Run pycodestyle test.py

test.py:3:3: E111 indentation is not a multiple of four
test.py:4:3: E111 indentation is not a multiple of four
test.py:6:3: E111 indentation is not a multiple of four