<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Contextlib on Nalar</title>
    <link>https://nalar.dev/tags/contextlib/</link>
    <description>Recent content in Contextlib on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 08 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/contextlib/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Change Working Directories Safely with contextlib.chdir</title>
      <link>https://nalar.dev/change-working-directories-safely-with-contextlib-chdir/</link>
      <pubDate>Tue, 08 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/change-working-directories-safely-with-contextlib-chdir/</guid>
      <description>&lt;p&gt;Changing the current working directory is one of those operations that looks local in code but is global in effect. I still see scripts that call &lt;code&gt;os.chdir()&lt;/code&gt;, do some work, and then try to remember where they started.&lt;/p&gt;&#xA;&lt;p&gt;Python 3.11 added &lt;code&gt;contextlib.chdir()&lt;/code&gt;, which makes the restore step much cleaner. To be fair, though, a context manager does not make changing the working directory concurrency-safe. The important part is understanding what state is being changed and how long that state stays changed.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
