<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Python on Joseph Hale</title>
    <link>https://thehale.dev/topics/python/</link>
    <description>Recent content in Python on Joseph Hale</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    
    
    
    
      <lastBuildDate>Mon, 17 Nov 2025 21:17:50 -0700</lastBuildDate>
    
    <atom:link href="https://thehale.dev/topics/python/index.xml" rel="self" type="application/rss+xml" />
      <item>
        <title>The emoji that broke my file uploads</title>
        <link>https://thehale.dev/guides/detecting-basic-multilingual-plane/</link>
        <pubDate>Fri, 09 May 2025 00:00:00 +0000</pubDate>
        <guid>https://thehale.dev/guides/detecting-basic-multilingual-plane/</guid>
        <description>&lt;h2 id=&#34;tldr&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#tldr&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&#xA;  TL;DR&#xA;  &lt;a class=&#34;hash&#34; href=&#34;#tldr&#34; aria-label=&#34;Link to this heading&#34; title=&#34;Link to this heading&#34; data-copy-title=&#34;Copy a link to this heading&#34;&gt;&lt;/a&gt;&#xA;&lt;/h2&gt;&#xA;&lt;div class=&#34;code-block&#34; style=&#34;--code-block-lang: &#39;Python&#39;&#34;&gt;&#xA;    &lt;div class=&#34;code-block-actions&#34;&gt;&#xA;    &lt;span class=&#34;code-block-lang&#34;&gt;Python&lt;/span&gt;&#xA;  &lt;button type=&#34;button&#34; class=&#34;code-block-copy&#34; aria-label=&#34;Copy code to clipboard&#34; title=&#34;Copy code&#34; hidden&gt;&#xA;    &lt;span class=&#34;active&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 448 512&#34;&gt;&lt;!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. --&gt;&lt;path d=&#34;M384 336l-192 0c-8.8 0-16-7.2-16-16l0-256c0-8.8 7.2-16 16-16l140.1 0L400 115.9 400 320c0 8.8-7.2 16-16 16zM192 384l192 0c35.3 0 64-28.7 64-64l0-204.1c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1L192 0c-35.3 0-64 28.7-64 64l0 256c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64L0 448c0 35.3 28.7 64 64 64l192 0c35.3 0 64-28.7 64-64l0-32-48 0 0 32c0 8.8-7.2 16-16 16L64 464c-8.8 0-16-7.2-16-16l0-256c0-8.8 7.2-16 16-16l32 0 0-48-32 0z&#34;/&gt;&lt;/svg&gt;&lt;/span&gt;&#xA;    &lt;span&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 448 512&#34;&gt;&lt;!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. --&gt;&lt;path d=&#34;M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z&#34;/&gt;&lt;/svg&gt;&lt;/span&gt;&#xA;  &lt;/button&gt;&#xA;&lt;/div&gt;&#xA;&#xA;  &#xA;  &#xA;  &#xA;  &#xA;  &#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; role=&#34;group&#34; aria-label=&#34;Python code&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;is_on_basic_multilingual_plane&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;char&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;char&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encode&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hex&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;16&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#34;mh&#34;&gt;0xFFFF&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h2 id=&#34;backstory&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#backstory&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&#xA;  Backstory&#xA;  &lt;a class=&#34;hash&#34; href=&#34;#backstory&#34; aria-label=&#34;Link to this heading&#34; title=&#34;Link to this heading&#34; data-copy-title=&#34;Copy a link to this heading&#34;&gt;&lt;/a&gt;&#xA;&lt;/h2&gt;&lt;p&gt;Recently, I was programmatically moving a few hundred thousand documents to a cloud service when my script caught an error about an invalid document name. Included in the error description was an esoteric &amp;ldquo;clarification&amp;rdquo; that this particular cloud service only supported filenames with characters in the &amp;ldquo;basic multilingual plane&amp;rdquo;.&lt;/p&gt;</description>
      </item>
      <item>
        <title>Python Script Output Redirection</title>
        <link>https://thehale.dev/guides/python-script-output-redirection/</link>
        <pubDate>Wed, 12 Feb 2025 00:00:00 +0000</pubDate>
        <guid>https://thehale.dev/guides/python-script-output-redirection/</guid>
        <description>&lt;figure&gt;&#xA;  &lt;blockquote cite=&#34;http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#:~:text=Write%20programs%20to%20handle%20text%20streams%2C%20because%20that%20is%20a%20universal%20interface.&#34;&gt;&#xA;    &#xA;      &lt;a href=&#34;http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#:~:text=Write%20programs%20to%20handle%20text%20streams%2C%20because%20that%20is%20a%20universal%20interface.&#34; aria-label=&#34;Go to Source&#34; title=&#34;Go to Source&#34;&gt;&#xA;        &lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 448 512&#34;&gt;&lt;!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. --&gt;&lt;path d=&#34;M448 296c0 66.3-53.7 120-120 120l-8 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l8 0c30.9 0 56-25.1 56-56l0-8-64 0c-35.3 0-64-28.7-64-64l0-64c0-35.3 28.7-64 64-64l64 0c35.3 0 64 28.7 64 64l0 32 0 32 0 72zm-256 0c0 66.3-53.7 120-120 120l-8 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l8 0c30.9 0 56-25.1 56-56l0-8-64 0c-35.3 0-64-28.7-64-64l0-64c0-35.3 28.7-64 64-64l64 0c35.3 0 64 28.7 64 64l0 32 0 32 0 72z&#34;/&gt;&lt;/svg&gt;&#xA;      &lt;/a&gt;&#xA;    &#xA;    &lt;p&gt;&amp;ldquo;Write programs to handle text streams, because that is a universal interface.&amp;rdquo;&lt;/p&gt;</description>
      </item>
      <item>
        <title>Solving a Tricky Email Invoicing Bug</title>
        <link>https://thehale.dev/essays/email-invoicing-debugging/</link>
        <pubDate>Thu, 09 Jan 2025 00:00:00 +0000</pubDate>
        <guid>https://thehale.dev/essays/email-invoicing-debugging/</guid>
        <description>&lt;p&gt;Solved a really involved bug today&amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;Some of our B2B customers were unable to email invoices to their clients, delaying incoming payments.&lt;/p&gt;&#xA;&lt;p&gt;My coworker traced the problem to the built-in Python function &lt;code&gt;email.utils.getaddresses&lt;/code&gt;, which was being used to extract email addresses from some text. In a test environment the function was returning the expected email addresses, but in production no emails were found.&lt;/p&gt;&#xA;&lt;p&gt;Adding to the confusion, Python&amp;rsquo;s &lt;code&gt;sys.version&lt;/code&gt; and &lt;code&gt;sys.implementation&lt;/code&gt; reported identical Python versions and builds in each environment. Additionally, scans of our code and our dependencies&amp;rsquo; code found no monkey-patches of the email parsing function. How could a built-in language function behave differently between apparently identical environments?&lt;/p&gt;</description>
      </item>
      <item>
        <title>Finding Python performance problems</title>
        <link>https://thehale.dev/guides/python-profiling/</link>
        <pubDate>Tue, 26 Mar 2024 00:00:00 +0000</pubDate>
        <guid>https://thehale.dev/guides/python-profiling/</guid>
        <description>&lt;p&gt;When a Python program is running too slowly, use a profiler to measure which parts of the code are hurting performance the most.&lt;/p&gt;&#xA;&lt;h2 id=&#34;measure-code-performance-with-cprofile&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#measure-code-performance-with-cprofile&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&#xA;  Measure Code Performance with &lt;code&gt;cProfile&lt;/code&gt;&#xA;  &lt;a class=&#34;hash&#34; href=&#34;#measure-code-performance-with-cprofile&#34; aria-label=&#34;Link to this heading&#34; title=&#34;Link to this heading&#34; data-copy-title=&#34;Copy a link to this heading&#34;&gt;&lt;/a&gt;&#xA;&lt;/h2&gt;&lt;p&gt;Start by writing a &lt;a href=&#34;https://realpython.com/primer-on-python-decorators/?utm_source=thehale.dev&amp;amp;utm_medium=newsletter&amp;amp;utm_campaign=python-profiling&#34; rel=&#34;noopener&#34; target=&#34;_blank&#34;&gt;&lt;span&gt;decorator&lt;/span&gt;&lt;span aria-hidden=&#34;true&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 512 512&#34;&gt;&lt;!--! Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. --&gt;&lt;path d=&#34;M320 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l82.7 0L201.4 265.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L448 109.3l0 82.7c0 17.7 14.3 32 32 32s32-14.3 32-32l0-160c0-17.7-14.3-32-32-32L320 0zM80 32C35.8 32 0 67.8 0 112L0 432c0 44.2 35.8 80 80 80l320 0c44.2 0 80-35.8 80-80l0-112c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 112c0 8.8-7.2 16-16 16L80 448c-8.8 0-16-7.2-16-16l0-320c0-8.8 7.2-16 16-16l112 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L80 32z&#34;/&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/a&gt; which will add profiling metrics to the decorated function:&lt;/p&gt;</description>
      </item>
  </channel>
</rss>
