Write Better Python
Treehouse
Course Summary
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.
-
+
Course Description
About this Course 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
About the Teacher
Besides teaching Python at Treehouse, Kenneth Love is a husband & father. He created a few popular Python libraries, worked at most levels of the web stack, & was the Creative Director of a newspaper. He likes board games, whiskey, activism, & dry humor.
-
+
Course 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. 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. 6 steps