Skip to content

Aug 25: PEP 8 Style Guide, ruff

Learning Objectives

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

  • Explain what a PEP is and why PEPs are important.
  • Run ruff 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 (Mon–Fri)
    • Ask and answer questions on Piazza (anytime)
  • Due tomorrow
    • Week 1 reading on Runestone
    • HW 1 on Runestone and Gradescope
  • Due Wednesday

Python Style Guide [10 min]

Mini Exercise

Fixing Style [20 min]

  • Download payroll.py
  • Run payroll.py first to see how it works
  • Run !ruff check 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 ruff by pressing Up+Enter in the shell
  • If you finish early, try making other style defects

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!