Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Treehouse

Write Better Python Course (How To)

via Treehouse

Overview

We've learned the ins and outs of Python. We're comfortable making all sorts of data types, writing functions, and creating classes. But now we need to look at how our Python code should be formatted so it matches the standard.

We'll also look at how to get our code to give us help() and how we can use logging and pdb to help us keep track of what's going on inside the code.

What you'll learn

  • The Python style guide and Zen rules
  • Docstrings
  • Logging
  • The Python Debugger

Syllabus

Cleaner Code

Writing Python is great but writing Python that fits the expected standard is even better. Let's learn about two PEPs that aim to make Python code cleaner, more beautiful, and smarter.

Chevron 10 steps
  • Let's Get Started

    0:51

  • PEP 8

    12:32

  • Indentation

    1 objective

  • Function and Class Whitespace

    1 objective

  • Operator Spacing

    1 objective

  • Imports

    1 objective

  • The Zen of Python

    2:32

  • Zen

    5 questions

  • Docstrings

    3:56

  • Docstrings

    2 objectives

  • Extra Credit

    Go back through the code you wrote for Python Basics, Python Collections, and Object-Oriented Python, and give all of the functions and classes docstrings. Make sure the rest of the code complies with PEP 8 as well.

Buggy Logs

It's a fact of programming: the more code you write, the more bugs you'll create. But letting your code talk to you about what's going on behind the scenes, using logging, and being able to step into your code, using a debugger, make your bugs a lot smaller and easier to squash.

Chevron 6 steps
  • Logging

    7:16

  • Log Messages

    2 objectives

  • The Python Debugger

    9:27

  • PDB

    1 objective

  • Wrap Up

    0:15

  • Review: Write Better Python

    5 questions

Reviews

Start your review of Write Better Python Course (How To)

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.