<?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 PythonTest</title>
    <link>https://pythontest.com/tags/python/</link>
    <description>Recent content in Python on PythonTest</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 11 Nov 2025 07:24:00 +0800</lastBuildDate>
    <atom:link href="https://pythontest.com/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Explore Python dependencies with `pipdeptree` and `uv pip tree`</title>
      <link>https://pythontest.com/pipdeptree-uv-pip-tree/</link>
      <pubDate>Tue, 11 Nov 2025 07:24:00 +0800</pubDate>
      <guid>https://pythontest.com/pipdeptree-uv-pip-tree/</guid>
      <description>&lt;p&gt;Sometimes you just want to know about your dependencies, and their dependencies.&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;ve been using &lt;code&gt;pipdeptree&lt;/code&gt; for a while, but recently switched to &lt;code&gt;uv pip tree&lt;/code&gt;.&lt;br&gt;&#xA;Let&amp;rsquo;s take a look at both tools.&lt;/p&gt;&#xA;&lt;h2 id=&#34;pipdeptree&#34;&gt;pipdeptree&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;pipdeptree&lt;/code&gt; is pip installable, but I don&amp;rsquo;t want &lt;code&gt;pipdeptree&lt;/code&gt; itself to be reported alongside everything else installed, so I usually install it outside of a project. We can use it system wide by:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Installing with &lt;code&gt;uv tool install pipdeptree&lt;/code&gt;.&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Then running with &lt;code&gt;pipdeptree --python auto&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Running without installing with &lt;code&gt;uvx pipdeptree --python auto&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;usage&#34;&gt;usage&lt;/h3&gt;&#xA;&lt;p&gt;The &lt;code&gt;--python auto&lt;/code&gt; tells &lt;code&gt;pipdeptree&lt;/code&gt; to look at the current environment.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Polite lazy imports for Python package maintainers</title>
      <link>https://pythontest.com/polite-lazy-imports-python-packages/</link>
      <pubDate>Sun, 26 Oct 2025 23:13:00 +0800</pubDate>
      <guid>https://pythontest.com/polite-lazy-imports-python-packages/</guid>
      <description>&lt;p&gt;If you are a maintainer of a Python package, it&amp;rsquo;s nice if you pay attention to the time it takes to import your package.&lt;/p&gt;&#xA;&lt;p&gt;Further, if you&amp;rsquo;ve got a Python package with multiple components where it&amp;rsquo;s probable that many users will only use part of the package, then it&amp;rsquo;s super nice if you set up your  &lt;code&gt;__init__.py&lt;/code&gt; files for lazy importing.&lt;/p&gt;&#xA;&lt;h2 id=&#34;previously---lazy-importing-other-packages&#34;&gt;Previously - lazy importing other packages&lt;/h2&gt;&#xA;&lt;p&gt;In &lt;a href=&#34;https://pythontest.com/python-lazy-imports-now&#34;&gt;Python lazy imports you can use today&lt;/a&gt;, I discussed:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Python lazy imports you can use today</title>
      <link>https://pythontest.com/python-lazy-imports-now/</link>
      <pubDate>Mon, 13 Oct 2025 19:00:00 +0800</pubDate>
      <guid>https://pythontest.com/python-lazy-imports-now/</guid>
      <description>&lt;p&gt;There&amp;rsquo;s a proposal, &lt;a href=&#34;https://peps.python.org/pep-0810/&#34;&gt;PEP 810 – Explicit lazy imports&lt;/a&gt; for Python to natively support lazy importing starting in Python 3.15.&lt;/p&gt;&#xA;&lt;p&gt;However, it has not been accepted yet, and even if it is accepted, 3.15 is a year away.&#xA;What do we do now?&lt;/p&gt;&#xA;&lt;p&gt;The techniques covered in this post that allow you to use lazy importing NOW with Python 3.13, Python 3.12, &amp;hellip;, really every version of Python.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s look at a small code example that imports something.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Installing Python 3.14 on Mac or Windows</title>
      <link>https://pythontest.com/python/installing-python-3-14/</link>
      <pubDate>Fri, 10 Oct 2025 20:14:00 +0800</pubDate>
      <guid>https://pythontest.com/python/installing-python-3-14/</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;The easiest way to install Python 3.14 (or 3.13, 3.12, 3.11, 3.10, 3.10, &amp;hellip;)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;I originally wrote this post in 2022 for Python 3.11.&lt;br&gt;&#xA;From 2022 through 2024, I remained of the belief that installing from python.org was the best option for most people.&lt;/p&gt;&#xA;&lt;p&gt;However, 2025 changed that for me, with &lt;code&gt;uv&lt;/code&gt; and &lt;code&gt;uv python&lt;/code&gt; supporting the installation of Python versions. It&amp;rsquo;s a really pleasant and clean way to keep Python versions up to date and install new versions.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Testing against Python 3.14</title>
      <link>https://pythontest.com/testing-with-python-3-14/</link>
      <pubDate>Fri, 10 Oct 2025 16:10:00 +0800</pubDate>
      <guid>https://pythontest.com/testing-with-python-3-14/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://docs.python.org/3.14/whatsnew/3.14.html#what-s-new-in-python-3-14&#34;&gt;Python 3.14&lt;/a&gt; is here.&lt;/p&gt;&#xA;&lt;p&gt;If you haven&amp;rsquo;t done so, it&amp;rsquo;s time to update your projects to test against 3.14.&lt;/p&gt;&#xA;&lt;p&gt;The following procedure is what I&amp;rsquo;m following for a handful of projects. Your process of course may be different if you use different tools.&lt;/p&gt;&#xA;&lt;p&gt;Honestly, I&amp;rsquo;m partly writing this down so I don&amp;rsquo;t have to remember it all in a year when 3.15 rolls around.&lt;/p&gt;&#xA;&lt;h2 id=&#34;installing-python-314&#34;&gt;Installing Python 3.14&lt;/h2&gt;&#xA;&lt;h3 id=&#34;installing-with-uv&#34;&gt;Installing with uv&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;uv self update&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;uv python install 3.14&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;While it&amp;rsquo;s true that creating a virtual environment with &lt;code&gt;uv venv .venv --python 3.14&lt;/code&gt; will install 3.14 if it isn&amp;rsquo;t already there, you still gotta run &lt;code&gt;uv self update&lt;/code&gt;. So I just usually install it while I&amp;rsquo;m at it.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Testing argparse Applications</title>
      <link>https://pythontest.com/testing-argparse-apps/</link>
      <pubDate>Thu, 16 Nov 2023 07:20:00 -0800</pubDate>
      <guid>https://pythontest.com/testing-argparse-apps/</guid>
      <description>&lt;p&gt;I was asked recently about how to test the argument parsing bit of an application that used &lt;a href=&#34;https://docs.python.org/3/library/argparse.html&#34;&gt;&lt;code&gt;argparse&lt;/code&gt;&lt;/a&gt;. &lt;code&gt;argparse&lt;/code&gt; is a built in Python library for dealing with parsing command line arguments for command line interfaces, CLI&amp;rsquo;s.&lt;/p&gt;&#xA;&lt;p&gt;You know, like &lt;code&gt;git clone &amp;lt;repo address&amp;gt;&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;git&lt;/code&gt; is the application.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;&amp;lt;repo address&amp;gt;&lt;/code&gt; is a command line argument.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;clone&lt;/code&gt; is a sub-command.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Well, that might be a bad example, as I&amp;rsquo;m not going to use subcommands in my example, but lots of this still applies, even if you are using subcommands. Anyway, loads of applications use command line arguments, also sometimes called flags and options.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Upgrading to Python 3.12 and my battle with virtualenv cache</title>
      <link>https://pythontest.com/posts/2023/2023-10-02-py312-impimporter/</link>
      <pubDate>Mon, 02 Oct 2023 12:29:07 -0700</pubDate>
      <guid>https://pythontest.com/posts/2023/2023-10-02-py312-impimporter/</guid>
      <description>&lt;p&gt;&lt;em&gt;edited Oct 3, 2023 with a new fix and a new understanding of the problem&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Initial title was &amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Python 3.12 + &amp;quot;AttributeError: module &amp;lsquo;pkgutil&amp;rsquo; has no attribute &amp;lsquo;ImpImporter&amp;rsquo;. Did you mean: &amp;lsquo;zipimporter&amp;rsquo;?&amp;quot;&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;This is a tale of upgrading Python 3.12&lt;/p&gt;&#xA;&lt;p&gt;I ran into this error while I was trying to update a project to test on Python 3.12:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  ...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  File &amp;#34;/Users/okken/Library/Application Support/virtualenv/wheel/house/pip-23.0.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py&amp;#34;, line 123, in _find_eggs_in_zip&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    from pip._vendor.pkg_resources import find_eggs_in_zip&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  File &amp;#34;/Users/okken/Library/Application Support/virtualenv/wheel/house/pip-23.0.1-py3-none-any.whl/pip/_vendor/pkg_resources/__init__.py&amp;#34;, line 2164, in &amp;lt;module&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    register_finder(pkgutil.ImpImporter, find_on_path)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;                    ^^^^^^^^^^^^^^^^^^^&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;AttributeError: module &amp;#39;pkgutil&amp;#39; has no attribute &amp;#39;ImpImporter&amp;#39;. Did you mean: &amp;#39;zipimporter&amp;#39;?&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;py312: internal error&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Specifically:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fixing Circular Imports in Python with Protocol</title>
      <link>https://pythontest.com/fix-circular-import-python-typing-protocol/</link>
      <pubDate>Mon, 23 Jan 2023 00:00:00 +0000</pubDate>
      <guid>https://pythontest.com/fix-circular-import-python-typing-protocol/</guid>
      <description>&lt;p&gt;The problem started when I had two classes that needed to talk to each other.  Sometimes, classes need to talk to each other in both directions.&lt;/p&gt;&#xA;&lt;p&gt;The following example is made up, but mostly behaves like the original problem.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s say I have a &lt;code&gt;Director&lt;/code&gt; and an &lt;code&gt;Actor&lt;/code&gt;.&lt;br&gt;&#xA;The &lt;code&gt;Director&lt;/code&gt; tells the &lt;code&gt;Actor&lt;/code&gt; to &lt;code&gt;do_action()&lt;/code&gt;.&lt;br&gt;&#xA;In order to do the action, the &lt;code&gt;Actor&lt;/code&gt; needs to &lt;code&gt;get_data()&lt;/code&gt; from the &lt;code&gt;Director&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Here&amp;rsquo;s our &lt;strong&gt;director.py&lt;/strong&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Testing with Python 3.12</title>
      <link>https://pythontest.com/testing-with-python-3-12/</link>
      <pubDate>Mon, 05 Dec 2022 00:00:00 +0000</pubDate>
      <guid>https://pythontest.com/testing-with-python-3-12/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://www.python.org/downloads/release/python-3120a2/&#34;&gt;Python 3.12.0a2&lt;/a&gt; is out. So now may be a great time to get your projects to start testing against 3.12.&lt;/p&gt;&#xA;&lt;h2 id=&#34;note-about-alpha-releases-of-python&#34;&gt;Note about alpha releases of Python&lt;/h2&gt;&#xA;&lt;p&gt;This is from &lt;a href=&#34;https://www.python.org/downloads/release/python-3120a2/&#34;&gt;the same link as above&lt;/a&gt;: &amp;ldquo;During the alpha phase, features may be added up until the start of the beta phase (2023-05-08) and, if necessary, may be modified or deleted up until the release candidate phase (2023-07-31). Please keep in mind that this is a preview release and its use is not recommended for production environments.&amp;rdquo;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Pinning Application Dependencies with pip-tools compile</title>
      <link>https://pythontest.com/python/pinning-applications-with-piptools-compile/</link>
      <pubDate>Wed, 09 Jun 2021 00:00:00 +0000</pubDate>
      <guid>https://pythontest.com/python/pinning-applications-with-piptools-compile/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/jazzband/pip-tools&#34;&gt;pip-tools&lt;/a&gt; has more functionality than this, but compile alone is quite useful.&lt;/p&gt;&#xA;&lt;p&gt;Start with a loose list of dependencies in &lt;code&gt;requirements.in&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;typer&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;rich&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;requirements.in&lt;/code&gt; file can have things like &lt;code&gt;&amp;gt;=&lt;/code&gt; and such if you have some restrictions on your dependencies.&lt;/p&gt;&#xA;&lt;p&gt;Now install &lt;code&gt;pip-tools&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pip install pip-tools&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, in create a &lt;code&gt;requirements.txt&lt;/code&gt; file with &lt;code&gt;compile&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pip-compile requirements.in&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;or:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python -m piptools compile requirements.in&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The output will be shown on stdout, but also in &lt;code&gt;requirements.txt&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>tip: dictionary get() works like getattr</title>
      <link>https://pythontest.com/python/dict-get-like-getattr/</link>
      <pubDate>Wed, 21 Aug 2013 19:14:26 +0000</pubDate>
      <guid>https://pythontest.com/python/dict-get-like-getattr/</guid>
      <description>&lt;p&gt;You can&amp;rsquo;t use &lt;code&gt;getattr()&lt;/code&gt; to look stuff up in a dictionary.&lt;br&gt;&#xA;But the &amp;lsquo;default&amp;rsquo; feature of &lt;code&gt;getattr()&lt;/code&gt; is so useful.&lt;br&gt;&#xA;What&amp;rsquo;s the dict way to do the same thing?&lt;/p&gt;&#xA;&lt;p&gt;This is one of &lt;a href=&#34;https://pythontest.com/python/annoyed-ternary-operator/&#34;&gt;those posts&lt;/a&gt; that I&amp;rsquo;m writing because I keep having to look it up.&lt;br&gt;&#xA;So if I write it, I&amp;rsquo;ll remember it. Hopefully.&lt;/p&gt;&#xA;&lt;h2 id=&#34;getattr&#34;&gt;getattr&lt;/h2&gt;&#xA;&lt;p&gt;I&amp;rsquo;ve been using the &amp;lsquo;default&amp;rsquo; parameter to getattr for some time, and it&amp;rsquo;s super handy.&lt;br&gt;&#xA;This is handy in lots of places, and avoids having to wrap things in try/except blocks.&lt;/p&gt;</description>
    </item>
    <item>
      <title>I’m annoyed with Python’s ternary operator</title>
      <link>https://pythontest.com/python/annoyed-ternary-operator/</link>
      <pubDate>Tue, 02 Jul 2013 16:14:23 +0000</pubDate>
      <guid>https://pythontest.com/python/annoyed-ternary-operator/</guid>
      <description>&lt;p&gt;The ternary operator is a way to concisely say:&lt;br&gt;&#xA;“If &lt;strong&gt;test&lt;/strong&gt;, then &lt;strong&gt;a&lt;/strong&gt;, else &lt;strong&gt;b&lt;/strong&gt;“,&lt;br&gt;&#xA;with the value of the statement being the value of &lt;strong&gt;a&lt;/strong&gt; or &lt;strong&gt;b&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;table&gt;&#xA;  &lt;thead&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;th&gt;language&lt;/th&gt;&#xA;          &lt;th&gt;how to say it&lt;/th&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/thead&gt;&#xA;  &lt;tbody&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;C&lt;/td&gt;&#xA;          &lt;td&gt;test ? a : b&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;C++&lt;/td&gt;&#xA;          &lt;td&gt;test ? a : b&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;javascript&lt;/td&gt;&#xA;          &lt;td&gt;test ? a : b&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;Perl (not perl 6)&lt;/td&gt;&#xA;          &lt;td&gt;test ? a : b&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;PHP&lt;/td&gt;&#xA;          &lt;td&gt;test ? a : b&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;Ruby&lt;/td&gt;&#xA;          &lt;td&gt;test ? a : b&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;Did I forget some language?&lt;/td&gt;&#xA;          &lt;td&gt;probably&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;Python&lt;/td&gt;&#xA;          &lt;td&gt;a if test else b &lt;strong&gt;(Why??)&lt;/strong&gt;&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;h2 id=&#34;why&#34;&gt;Why??&lt;/h2&gt;&#xA;&lt;p&gt;Ok. Now that I’ve written this post, I’ll remember it.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Python regex Search and Replace Examples</title>
      <link>https://pythontest.com/python/regex-search-replace/</link>
      <pubDate>Fri, 08 Feb 2013 00:00:00 +0000</pubDate>
      <guid>https://pythontest.com/python/regex-search-replace/</guid>
      <description>&lt;p&gt;Search and replace is such a common task that it should be a tool that&amp;rsquo;s in every command line script author&amp;rsquo;s toolbox.&lt;br&gt;&#xA;There are probably endless solutions to the problem.&lt;br&gt;&#xA;I&amp;rsquo;ve put together my standard methods for tackling the problem.&lt;br&gt;&#xA;I&amp;rsquo;ll also show similar Perl versions, mainly for comparisons.&lt;/p&gt;&#xA;&lt;h2 id=&#34;use-models&#34;&gt;use models&lt;/h2&gt;&#xA;&lt;p&gt;In most of the following discussion, I&amp;rsquo;m just replacing &amp;lsquo;foo&amp;rsquo; with &amp;lsquo;bar&amp;rsquo;.&lt;br&gt;&#xA;&lt;strong&gt;However &amp;lsquo;foo&amp;rsquo; can be ANY regular expression.&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
