Skip to content

Aug 28: PEP 8 Style Guide, flake8

Learning Objectives

After today's class, you should be able to:

  • Explain what a PEP is and why PEPs are important
  • Run flake8 to check your code before submitting
  • Describe at least three style guidelines for Python

Mini Lecture

Announcements [10 min]

  • See the Help page:
    • TA Hours (Sun–Thu) and Office Hours (Tue/Thu)
    • Ask and answer questions on Piazza (anytime)
  • Due tomorrow
  • Due Wednesday

Python Style Guide [10 min]

Mini Exercise

Fixing Style [20 min]

  • Download payroll.py and setup.cfg
  • Run payroll.py first to see how it works
  • Run !flake8 payroll.py in the shell
    • You should see several lines of output
    • payroll.py:4:18 means "Line 4, Char 18"
  • Correct each issue, one by one, in the editor
    • Rerun flake8 by pressing Up+Enter in the shell
  • If you finish early, delete setup.cfg and go all the way PEP 8
    • Our config does not enforce all of PEP 8's requirements

Thonny Tips

Quick Demo [10 min]

  • Have you discovered the View menu in Thonny?
    • Consider showing "Files" and "Variables"
    • Other windows might be useful to you
  • Tools > Options… Theme & Font
    • UI theme: Clean Dark
    • Syntax theme: Tomorrow Night Eighties
    • Feel free to choose the ones you want!