The Real Python Podcast

Creating Tic-Tac-Toe With an AI Player & Shortcuts for Python Decorators


Listen Later

How do you create a computer opponent for a simple game within Python? Would you also like to learn how to adapt the game to run in a web browser or graphical user interface (GUI)? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder’s Weekly articles and projects.

Christopher shares a recent Real Python step-by-step project for creating a tic-tac-toe game engine. He talks about how to build the game engine and adapt it for different front ends. The tutorial also shows how to implement an unbeatable computer player using the minimax algorithm.

We discuss an article about how to avoid repeating yourself when creating decorators with multiple parameters. We talk about how you can stop copying and pasting code several times by assigning the decorator to a new variable.

We share several other articles and projects from the Python community, including a news roundup, a deep dive into Python’s doctest, several Python command line tricks, type annotations via automated refactoring, a new way to draw boxes in the terminal, a collection of projects for beginners with source code, a minimalist PDF creation library, and a tool for sensible logging in Python.

Course Spotlight: Python Decorators 101

In this course on Python decorators, you’ll learn what they are and how to create and use them. Decorators provide a simple syntax for calling higher-order functions in Python. By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.

Topics:

  • 00:00:00 – Introduction
  • 00:02:25 – Python 3.12.0 Alpha 1 Released
  • 00:02:45 – PyCon US 2023 Call for Proposals
  • 00:03:27 – Python’s doctest: Document and Test Your Code at Once
  • 00:13:59 – Build a Tic-Tac-Toe Game Engine With an AI Player in Python
  • 00:22:12 – Sponsor: InfluxDB
  • 00:22:59 – Python Command Line Tricks
  • 00:30:50 – Type Annotation via Automated Refactoring
  • 00:34:29 – A New (?) Way of Drawing Boxes in the Terminal
  • 00:37:10 – Decorator Shortcuts
  • 00:39:36 – Video Course Spotlight
  • 00:41:02 – 190 Python Projects With Source Code
  • 00:47:58 – fpdf2: Minimalist PDF Creation Library
  • 00:50:04 – Simple, Sane, and Sensible Logging in Python
  • 00:53:05 – Thanks and goodbye
  • News:

    • Python 3.12.0 Alpha 1 Released
    • PyCon US 2023 Call for Proposals
    • Topics:

      • Python’s doctest: Document and Test Your Code at Once – In this tutorial, you’ll learn how to add usage examples to your code’s documentation and docstrings and how to use these examples to test your code. To run your usage examples as automated tests, you’ll use Python’s doctest module from the standard library.
      • Build a Tic-Tac-Toe Game Engine With an AI Player in Python – In this step-by-step tutorial, you’ll build a universal game engine in Python with tic-tac-toe rules and two computer players, including an unbeatable AI player using the minimax algorithm. You’ll also create a text-based graphical front end for your library and explore two alternative front ends.
      • Python Command Line Tricks – Using python -m you can do all sorts of things from the command line, including starting a webserver, opening a browser, parsing JSON, compressing files, and much more.
      • Type Annotation via Automated Refactoring – Jimmy’s team at Carta decided they wanted to add type annotations to their large codebase, but doing so manually would’ve taken a very long time. This post shows you how they built automated refactoring tools to add type annotations to their code.
      • A New (?) Way of Drawing Boxes in the Terminal – With clever use of some of the Unicode border characters, you can build a better box around your text, without any color bleeding.
      • Decorator Shortcuts – “When using many decorators in code, there’s a shortcut you can use if you find yourself repeating them. They can be assigned to a variable just like any other Python expression.”
      • Discussion:

        • 190 Python Projects With Source Code
        • Projects:

          • fpdf2: Minimalist PDF Creation Library
          • Simple, Sane, and Sensible Logging in Python – Get started with logging in Python or deploy advanced, flexible loggers without the boilerplate code. Learn all about log2d, a third-party wrapper for the Python logging library.
          • Additional Links:

            • Build Your Python Project Documentation With MkDocs – Real Python
            • Episode #97: Improving Your Django and Python Developer Experience – The Real Python Podcast
            • Python’s zipapp: Build Executable Zip Applications – Real Python
            • Episode #80: Make Your Python App Interactive With a Text User Interface (TUI) – The Real Python Podcast
            • Episode #20: Building PDFs in Python with ReportLab – The Real Python Podcast
            • Links for Documentation FPDF and Other Ports
            • PFython/log2d - GitHub
            • Level up your Python skills with our expert-led courses:

              • How to Work With a PDF in Python
              • Python Inner Functions
              • Python Decorators 101
              • 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

                625 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

                296 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

                983 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