The Real Python Podcast

Start Testing Your Python with doctest & Pagination in Django


Listen Later

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:

  • 00:00:00 – Introduction
  • 00:02:15 – PyCon US 2022 Follow-up
  • 00:07:57 – Why Is It Important to Close Files in Python?
  • 00:15:17 – Dunder Methods in Python: The Ugliest Awesome Sauce
  • 00:24:26 – Sponsor: Mailtrap
  • 00:25:08 – Python Testing With doctest
  • 00:28:20 – Python Bidirectional Dictionary
  • 00:30:27 – Pagination for a User-Friendly Django App
  • 00:36:07 – Video Course Spotlight
  • 00:37:27 – Python’s “Type Hints” are a bit of a disappointment to me
  • 00:52:25 – dunk: Prettier Git Diffs
  • 00:53:43 – git-gud: Command-Line Game to Learn git
  • 00:55:40 – Thanks and goodbye
  • Topic Links:

    • Why Is It Important to Close Files in Python? – 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.
    • Dunder Methods in Python: The Ugliest Awesome Sauce – Double-underscore methods, also known as “dunder methods” or “magic methods” are an ugly way of bringing beauty to your code. Learn about constructors, __repr__, __str__, operator overloading, and getting your classes working with Python functions like len().
    • Python Testing With doctest – Python’s 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.
    • Python Bidirectional Dictionary – 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.
    • Pagination for a User-Friendly Django App – 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.
    • Discussion:

      • Python’s “Type Hints” are a bit of a disappointment to me | Original Article
      • Python’s “Type Hints” | Lobsters Thread
      • Python’s “Type Hints” | Hacker News Thread
      • Projects:

        • dunk: Prettier Git Diffs
        • git-gud: Command-Line Game to Learn git
        • Additional Links:

          • Episode #47: Unraveling Python’s Syntax to Its Core With Brett Cannon – The Real Python Podcast
          • Python Coding Interviews: Tips & Best Practices – Real Python
          • Episode #88: Discussing Type Hints, Protocols, and Ducks in Python – The Real Python Podcast
          • Up and Running with Git Online Course - Talk Python Training
          • Python’s doctest: Document and Test Your Code at Once - Real Python tutorial
          • Level up your Python skills with our expert-led courses:

            • Python Type Checking
            • Python Coding Interviews: Tips & Best Practices
            • Testing Your Code With pytest
            • Support the podcast & join our community of Pythonistas

              ...more
              View all episodesView all episodes
              Download on the App Store

              The Real Python PodcastBy Real Python

              • 4.7
              • 4.7
              • 4.7
              • 4.7
              • 4.7

              4.7

              136 ratings


              More shows like The Real Python Podcast

              View all
              Software Engineering Radio - the podcast for professional software developers by se-radio@computer.org

              Software Engineering Radio - the podcast for professional software developers

              272 Listeners

              The Changelog: Software Development, Open Source by Changelog Media

              The Changelog: Software Development, Open Source

              283 Listeners

              Thoughtworks Technology Podcast by Thoughtworks

              Thoughtworks Technology Podcast

              41 Listeners

              Talk Python To Me by Michael Kennedy

              Talk Python To Me

              592 Listeners

              Software Engineering Daily by Software Engineering Daily

              Software Engineering Daily

              624 Listeners

              Soft Skills Engineering by Jamison Dance and Dave Smith

              Soft Skills Engineering

              269 Listeners

              Super Data Science: ML & AI Podcast with Jon Krohn by Jon Krohn

              Super Data Science: ML & AI Podcast with Jon Krohn

              298 Listeners

              Python Bytes by Michael Kennedy and Brian Okken

              Python Bytes

              213 Listeners

              Data Engineering Podcast by Tobias Macey

              Data Engineering Podcast

              142 Listeners

              Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

              Syntax - Tasty Web Development Treats

              982 Listeners

              DataFramed by DataCamp

              DataFramed

              266 Listeners

              Kubernetes Podcast from Google by Abdel Sghiouar, Kaslin Fields

              Kubernetes Podcast from Google

              181 Listeners

              Practical AI by Practical AI LLC

              Practical AI

              189 Listeners

              The Stack Overflow Podcast by The Stack Overflow Podcast

              The Stack Overflow Podcast

              64 Listeners

              The Pragmatic Engineer by Gergely Orosz

              The Pragmatic Engineer

              52 Listeners