
Episode 149
Coding With namedtuple & Python's Dynamic Superpowers
The Real Python Podcast · Real Python
March 17, 202353m 17s
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>Have you explored Python’s collections module? Within it, you’ll find a powerful factory function called namedtuple(), which provides multiple enhancements over the standard tuple for writing clearer and cleaner code. This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder’s Weekly articles and projects.</p>
<p>Christopher discusses his Real Python video course about writing more Pythonic code using <code>namedtuple()</code>. With namedtuple(), you can create immutable sequence types that allow you to access their values using descriptive field names and dot notation instead of clunky integer indices.</p>
<p>We also discuss metaprogramming and the unique advantages of Python’s dynamism. Christopher shares potential paths for this type of coding from web applications, testing, and AST techniques. </p>
<p>We share several other articles and projects from the Python community, including a news update, the Arrow revolution happening in pandas 2.0, a new PEP for inlined comprehensions, tips and techniques for modern Flask apps, a Python helper tool for building and running a REPL with custom commands, and a project to turn a pandas DataFrame into a Tableau-style UI.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Course Spotlight:</strong> <a href="https://realpython.com/courses/python-namedtuple/">Writing Clean, Pythonic Code With <code>namedtuple</code></a></p>
<p>In this video course, you’ll learn what Python’s <code>namedtuple</code> is and how to use it in your code. You’ll also learn about the main differences between named tuples and other data structures, such as dictionaries, data classes, and typed named tuples.</p>
</div>
<p>Topics:</p>
<ul>
<li>00:00:00 – Introduction</li>
<li>00:02:17 – Python 3.12.0 alpha 6 released</li>
<li>00:02:40 – Django Developers Survey 2022 Results</li>
<li>00:03:12 – Writing Clean, Pythonic Code With <code>namedtuple</code></li>
<li>00:07:40 – pandas 2.0 and the Arrow Revolution (Part I)</li>
<li>00:17:21 – Sponsor: RevSys</li>
<li>00:18:10 – PEP 709: Inlined Comprehensions</li>
<li>00:20:51 – 13 Tips and Techniques for Modern Flask Apps</li>
<li>00:25:54 – Video Course Spotlight</li>
<li>00:27:24 – Discussion: Python’s “Disappointing” Superpowers</li>
<li>00:47:54 – replbuilder: Python helper tool for building and running a REPL with custom commands</li>
<li>00:49:58 – pygwalker: Turn pandas Into a Tableau-Style UI </li>
<li>00:52:15 – Thanks and goodbye</li>
</ul>
<p>News:</p>
<ul>
<li><a href="https://pythoninsider.blogspot.com/2023/03/python-3120-alpha-6-released.html">Python Insider: Python 3.12.0 alpha 6 released</a></li>
<li><a href="https://www.djangoproject.com/weblog/2023/mar/09/django-developers-survey-2022-results/?utm_campaign=Django%2BNewsletter&utm_medium=email&utm_source=Django_Newsletter_170">Django Developers Survey 2022 Results - Django Weblog</a></li>
</ul>
<p>Show Links:</p>
<ul>
<li><a href="https://realpython.com/courses/python-namedtuple/">Writing Clean, Pythonic Code With <code>namedtuple</code></a> – In this video course, you’ll learn what Python’s <code>namedtuple</code> is and how to use it in your code. You’ll also learn about the main differences between named tuples and other data structures, such as dictionaries, data classes, and typed named tuples.</li>
<li><a href="https://datapythonista.me/blog/pandas-20-and-the-arrow-revolution-part-i">pandas 2.0 and the Arrow Revolution (Part I)</a> – This article details the changes in the pandas 2.0 release, with emphasis on the underlying adoption of Apache Arrow.</li>
<li><a href="https://peps.python.org/pep-0709/">PEP 709: Inlined Comprehensions</a> – Python Enhancement Proposal 709 covers a change to how comprehensions are handled. Currently, they’re compiled as nested functions. Benchmarking shows that treating <code>list</code>, <code>dict</code>, and <code>set</code> comprehensions as inline code can result in a 2x speedup on the comprehension.</li>
<li><a href="https://pgjones.dev/blog/modern-flask-2023/">13 Tips and Techniques for Modern Flask Apps</a> – Flask is approaching its 13th birthday, and to celebrate, Phillip has written 13 tips for writing modern Flask apps. It covers dealing with JSON, environment-based configuration, auto-generated docs, and more.</li>
</ul>
<p>Discussion:</p>
<ul>
<li><a href="https://lukeplant.me.uk/blog/posts/pythons-disappointing-superpowers/">Python’s “Disappointing” Superpowers - lukeplant.me.uk</a></li>
<li><a href="https://buttondown.email/hillelwayne/archive/i-am-disappointed-by-dynamic-typing/">I am disappointed by dynamic typing - Buttondown</a></li>
<li><a href="https://news.ycombinator.com/item?id=34611969">Python’s “Disappointing” superpowers - Hacker News</a></li>
<li><a href="https://lobste.rs/s/9w7ylg/python_s_disappointing_superpowers">Python’s “Disappointing” Superpowers - Lobsters</a></li>
</ul>
<p>Projects:</p>
<ul>
<li><a href="https://github.com/Aperocky/replbuilder">replbuilder: Python helper tool for building and running a repl with custom commands</a></li>
<li><a href="https://github.com/Kanaries/pygwalker">pygwalker: Turn pandas Into a Tableau-Style UI</a></li>
</ul>
<p>Additional Links:</p>
<ul>
<li><a href="https://realpython.com/python-namedtuple/">Write Pythonic and Clean Code With namedtuple – Real Python</a></li>
<li><a href="https://realpython.com/podcasts/rpp/146/">Episode #146: Using NumPy and Linear Algebra for Faster Python Code – The Real Python Podcast</a></li>
<li><a href="https://wesmckinney.com/blog/apache-arrow-pandas-internals/">Apache Arrow and the “10 Things I Hate About pandas” - Wes McKinney</a></li>
<li><a href="https://www.youtube.com/watch?v=wdmf1msbtVs">Data science without borders - Wes McKinney (Two Sigma Investments) - YouTube</a></li>
<li><a href="https://wesmckinney.com/blog/from-ursa-to-voltrondata/">Joining Forces for an Arrow-Native Future - Wes McKinney</a></li>
<li><a href="https://pandas.pydata.org/docs/dev/reference/arrays.html?highlight=arrowdtype#pyarrow">pandas arrays, scalars, and data types — pandas 2.1.0.dev0+171.gc293caf2e9 documentation</a></li>
<li><a href="https://realpython.com/podcasts/rpp/18/">Episode #18: Ten Years of Flask: Conversation With Creator Armin Ronacher – The Real Python Podcast</a></li>
<li><a href="https://realpython.com/flask-connexion-rest-api/">Python REST APIs With Flask, Connexion, and SQLAlchemy – Part 1 – Real Python</a></li>
<li><a href="https://realpython.com/python-metaclasses/">Python Metaclasses – Real Python</a></li>
<li><a href="https://kanaries.net/">Kanaries AI enhanced data exploration</a></li>
</ul>
<p>Level up your Python skills with our expert-led courses:</p>
<ul>
<li><a href="https://realpython.com/courses/data-cleaning-with-pandas-and-numpy/">Data Cleaning With pandas and NumPy</a></li>
<li><a href="https://realpython.com/courses/lists-tuples-python/">Lists and Tuples in Python</a></li>
<li><a href="https://realpython.com/courses/python-namedtuple/">Writing Clean, Pythonic Code With namedtuple</a></li>
</ul> <p><a rel="payment" href="https://realpython.com/join">Support the podcast & join our community of Pythonistas</a></p>