Did you know you can add testing to your Python code while simultaneously documenting it? Using docstrings, you can create examples of how your functions should interact in a Python REPL and test them with the built-in doctest module. This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder’s Weekly articles and projects.
Christopher shares an article by previous guest Mike Driscoll about testing with doctest. This is a great way to get started with testing your own code, and it offers the added benefit of documenting functionality.
We talk about the recent Real Python article “Pagination for a User-Friendly Django App.” Spreading your content across multiple pages can significantly improve the user experience of your web application. This article takes you through configuring Django’s built-in pagination tool and how to combine it with other web tools.
We discuss a recent article about Python type hints and the author’s disappointment. We also include reactions from a couple of online communities.
We cover several other articles and projects from the Python community, including why it’s important to close files in Python, how dunder methods are awesome, a bidirectional Python dictionary, prettier git diffs, and a command-line game to learn git.
Spotlight: Python Coding Interviews: Tips & Best Practices
In this step-by-step course, you’ll learn how to take your Python coding interview skills to the next level and use Python’s built-in functions and modules to solve problems faster and more easily.
Topics:
Topic Links:
__repr__
, __str__
, operator overloading, and getting your classes working with Python functions like len()
.doctest
module allows you to write unit tests through REPL-like sessions in your docstrings. Learn how to write and execute doctest
code. Also available in video.Discussion:
Projects:
Additional Links:
Level up your Python skills with our expert-led courses: