
Episode 109
Start Testing Your Python with doctest & Pagination in Django
The Real Python Podcast · Real Python
May 13, 202256m 39s
Audio is streamed directly from the publisher (dts.podtrac.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.
Show Notes
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>We discuss a recent article about Python type hints and the author’s disappointment. We also include reactions from a couple of online communities.</p>
<p>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.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Spotlight:</strong> <a href="https://realpython.com/courses/python-coding-interviews-tips-best-practices/">Python Coding Interviews: Tips & Best Practices</a></p>
<p>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.</p>
</div>
<p>Topics:</p>
<ul>
<li>00:00:00 – Introduction</li>
<li>00:02:15 – PyCon US 2022 Follow-up</li>
<li>00:07:57 – Why Is It Important to Close Files in Python?</li>
<li>00:15:17 – Dunder Methods in Python: The Ugliest Awesome Sauce</li>
<li>00:24:26 – Sponsor: Mailtrap</li>
<li>00:25:08 – Python Testing With doctest</li>
<li>00:28:20 – Python Bidirectional Dictionary</li>
<li>00:30:27 – Pagination for a User-Friendly Django App</li>
<li>00:36:07 – Video Course Spotlight</li>
<li>00:37:27 – Python’s “Type Hints” are a bit of a disappointment to me </li>
<li>00:52:25 – dunk: Prettier Git Diffs</li>
<li>00:53:43 – git-gud: Command-Line Game to Learn git</li>
<li>00:55:40 – Thanks and goodbye</li>
</ul>
<p>Topic Links:</p>
<ul>
<li><a href="https://realpython.com/why-close-file-python/">Why Is It Important to Close Files in Python?</a> – Model citizens use context managers to open and close file resources in Python, but have you ever wondered why it’s important to close files? In this tutorial, you’ll take a deep dive into the reasons why it’s important to close files and what can happen if you dont.</li>
<li><a href="https://codesolid.com/dunder-methods-in-python-the-ugliest-awesome-sauce/">Dunder Methods in Python: The Ugliest Awesome Sauce</a> – Double-underscore methods, also known as “dunder methods” or “magic methods” are an ugly way of bringing beauty to your code. Learn about constructors, <code>__repr__</code>, <code>__str__</code>, operator overloading, and getting your classes working with Python functions like <code>len()</code>.</li>
<li><a href="https://www.blog.pythonlibrary.org/2014/03/17/python-testing-with-doctest/">Python Testing With doctest</a> – Python’s <code>doctest</code> module allows you to write unit tests through REPL-like sessions in your docstrings. Learn how to write and execute <code>doctest</code> code. Also available in <a href="https://www.blog.pythonlibrary.org/2022/04/05/intro-to-testing-python-with-doctest-video/">video</a>.</li>
<li><a href="https://towardsdatascience.com/python-bi-dictionary-key-can-be-value-and-value-can-be-key-50715a2046af">Python Bidirectional Dictionary</a> – Learn about the Bidict library, a bidirectional dictionary where your keys and your values can both be used to look up an item. This can be a useful tool when dealing with mapped data, like country code to country name, where you want to look up either side of the relationship.</li>
<li><a href="https://realpython.com/django-pagination/">Pagination for a User-Friendly Django App</a> – In this tutorial, you’ll learn how to serve paginated content in your Django apps. Using Django pagination can significantly improve your website’s performance and give your visitors a better user experience.</li>
</ul>
<p>Discussion:</p>
<ul>
<li><a href="https://www.uninformativ.de/blog/postings/2022-04-21/0/POSTING-en.html">Python’s “Type Hints” are a bit of a disappointment to me | Original Article</a></li>
<li><a href="https://lobste.rs/s/uxnepo/python_s_type_hints_are_bit">Python’s “Type Hints” | Lobsters Thread</a></li>
<li><a href="https://news.ycombinator.com/item?id=31114554">Python’s “Type Hints” | Hacker News Thread</a></li>
</ul>
<p>Projects:</p>
<ul>
<li><a href="https://github.com/darrenburns/dunk">dunk: Prettier Git Diffs</a></li>
<li><a href="https://github.com/benthayer/git-gud">git-gud: Command-Line Game to Learn git</a></li>
</ul>
<p>Additional Links:</p>
<ul>
<li><a href="https://realpython.com/podcasts/rpp/47/">Episode #47: Unraveling Python’s Syntax to Its Core With Brett Cannon – The Real Python Podcast</a></li>
<li><a href="https://realpython.com/courses/python-coding-interviews-tips-best-practices/">Python Coding Interviews: Tips & Best Practices – Real Python</a></li>
<li><a href="https://realpython.com/podcasts/rpp/88/">Episode #88: Discussing Type Hints, Protocols, and Ducks in Python – The Real Python Podcast</a></li>
<li><a href="https://training.talkpython.fm/courses/up-and-running-with-git-a-pragmatic-ui-based-introduction">Up and Running with Git Online Course - Talk Python Training</a></li>
<li><a href="https://realpython.com/python-doctest/">Python’s doctest: Document and Test Your Code at Once - Real Python tutorial</a></li>
</ul>
<p>Level up your Python skills with our expert-led courses:</p>
<ul>
<li><a href="https://realpython.com/courses/python-type-checking/">Python Type Checking</a></li>
<li><a href="https://realpython.com/courses/python-coding-interviews-tips-best-practices/">Python Coding Interviews: Tips & Best Practices</a></li>
<li><a href="https://realpython.com/courses/testing-your-code-with-pytest/">Testing Your Code With pytest</a></li>
</ul> <p><a rel="payment" href="https://realpython.com/join">Support the podcast & join our community of Pythonistas</a></p>