PLAY PODCASTS
Start Testing Your Python with doctest & Pagination in Django
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&rsquo;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 &ldquo;Pagination for a User-Friendly Django App.&rdquo; Spreading your content across multiple pages can significantly improve the user experience of your web application. This article takes you through configuring Django&rsquo;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&rsquo;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&rsquo;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 &amp; Best Practices</a></p> <p>In this step-by-step course, you&rsquo;ll learn how to take your Python coding interview skills to the next level and use Python&rsquo;s built-in functions and modules to solve problems faster and more easily.</p> </div> <p>Topics:</p> <ul> <li>00:00:00 &ndash; Introduction</li> <li>00:02:15 &ndash; PyCon US 2022 Follow-up</li> <li>00:07:57 &ndash; Why Is It Important to Close Files in Python?</li> <li>00:15:17 &ndash; Dunder Methods in Python: The Ugliest Awesome Sauce</li> <li>00:24:26 &ndash; Sponsor: Mailtrap</li> <li>00:25:08 &ndash; Python Testing With doctest</li> <li>00:28:20 &ndash; Python Bidirectional Dictionary</li> <li>00:30:27 &ndash; Pagination for a User-Friendly Django App</li> <li>00:36:07 &ndash; Video Course Spotlight</li> <li>00:37:27 &ndash; Python&rsquo;s &ldquo;Type Hints&rdquo; are a bit of a disappointment to me </li> <li>00:52:25 &ndash; dunk: Prettier Git Diffs</li> <li>00:53:43 &ndash; git-gud: Command-Line Game to Learn git</li> <li>00:55:40 &ndash; 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> &ndash; Model citizens use context managers to open and close file resources in Python, but have you ever wondered why it&rsquo;s important to close files? In this tutorial, you&rsquo;ll take a deep dive into the reasons why it&rsquo;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> &ndash; Double-underscore methods, also known as &ldquo;dunder methods&rdquo; or &ldquo;magic methods&rdquo; 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> &ndash; Python&rsquo;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> &ndash; 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> &ndash; In this tutorial, you&rsquo;ll learn how to serve paginated content in your Django apps. Using Django pagination can significantly improve your website&rsquo;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&rsquo;s &ldquo;Type Hints&rdquo; 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&rsquo;s &ldquo;Type Hints&rdquo; | Lobsters Thread</a></li> <li><a href="https://news.ycombinator.com/item?id=31114554">Python&rsquo;s &ldquo;Type Hints&rdquo; | 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&rsquo;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 &amp; 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&rsquo;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 &amp; 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 &amp; join our community of Pythonistas</a></p>