<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pathlib | Haobin Tan</title><link>https://haobin-tan.netlify.app/tags/pathlib/</link><atom:link href="https://haobin-tan.netlify.app/tags/pathlib/index.xml" rel="self" type="application/rss+xml"/><description>Pathlib</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Sat, 26 Dec 2020 00:00:00 +0000</lastBuildDate><image><url>https://haobin-tan.netlify.app/media/icon_hu7d15bc7db65c8eaf7a4f66f5447d0b42_15095_512x512_fill_lanczos_center_3.png</url><title>Pathlib</title><link>https://haobin-tan.netlify.app/tags/pathlib/</link></image><item><title>pathlib</title><link>https://haobin-tan.netlify.app/docs/coding/python/files/pathlib/</link><pubDate>Sat, 26 Dec 2020 00:00:00 +0000</pubDate><guid>https://haobin-tan.netlify.app/docs/coding/python/files/pathlib/</guid><description>&lt;h2 id="why-patblib">Why &lt;code>patblib&lt;/code>?&lt;/h2>
&lt;p>The &lt;code>pathlib&lt;/code> module, introduced in Python 3.4 (&lt;a href="https://www.python.org/dev/peps/pep-0428/">PEP 428&lt;/a>), gathers the necessary functionality in one place and makes it available through methods and properties on an easy-to-use &lt;code>Path&lt;/code> object.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">pathlib&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Path&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="createing-paths">Createing paths&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Use class methods:&lt;/p>
&lt;ul>
&lt;li>&lt;code>Path.cwd()&lt;/code>: get Current Working Directory&lt;/li>
&lt;li>&lt;code>Path.home()&lt;/code>: get home directory&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Create from string representation explicitly&lt;/p>
&lt;p>E.g.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">Path&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;/content/src/demo.py&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Construct path by joining parts of the path&lt;/p>
&lt;p>E.g.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">Path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">joinpath&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">cwd&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="s2">&amp;#34;src&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;demo.py&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;/ul>
&lt;h2 id="reading-and-writing-files">Reading and writing files&lt;/h2>
&lt;p>The built-in &lt;code>open()&lt;/code> function can use &lt;code>Path&lt;/code> objects directly. E.g.:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">with&lt;/span> &lt;span class="nb">open&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">mode&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;r&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">f&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">pass&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>For simple reading and writing of files, there are a couple of convenience methods in the &lt;code>pathlib&lt;/code> library:&lt;/p>
&lt;ul>
&lt;li>&lt;code>.read_text()&lt;/code>: open the path in text mode and return the contents as a string.&lt;/li>
&lt;li>&lt;code>.read_bytes()&lt;/code>: open the path in binary/bytes mode and return the contents as a bytestring.&lt;/li>
&lt;li>&lt;code>.write_text()&lt;/code>: open the path and write string data to it.&lt;/li>
&lt;li>&lt;code>.write_bytes()&lt;/code>: open the path in binary/bytes mode and write data to it.&lt;/li>
&lt;/ul>
&lt;p>Each of these methods handles the opening and closing of the file, making them trivial to use.&lt;/p>
&lt;h2 id="components-of-path">Components of path&lt;/h2>
&lt;p>The different parts of a path are conveniently available as properties. Basic examples include:&lt;/p>
&lt;ul>
&lt;li>&lt;code>.name&lt;/code>: the file name without any directory&lt;/li>
&lt;li>&lt;code>.parent&lt;/code>: the directory containing the file, or the parent directory if path is a directory&lt;/li>
&lt;li>&lt;code>.stem&lt;/code>: the file name without the suffix&lt;/li>
&lt;li>&lt;code>.suffix&lt;/code>: the file extension&lt;/li>
&lt;li>&lt;code>.anchor&lt;/code>: the part of the path before the directories&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">path&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">Path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">joinpath&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">cwd&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="s2">&amp;#34;src&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;hello-world.txt&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;Full path: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;Name: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;Parent: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">parent&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;Stem: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">stem&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;Suffix: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">suffix&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;Anchor: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">anchor&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Full path: /content/src/hello-world.txt
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Name: hello-world.txt
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Parent: /content/src
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Stem: hello-world
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Suffix: .txt
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Anchor: /
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="renaming-files">Renaming files&lt;/h2>
&lt;p>When you are renaming files, useful methods might be &lt;code>.with_name()&lt;/code> and &lt;code>.with_suffix()&lt;/code>. They both return the original path but with the name or the suffix replaced, respectively.&lt;/p>
&lt;h2 id="deleting-files">Deleting files&lt;/h2>
&lt;p>Directories and files can be deleted using &lt;code>.rmdir()&lt;/code> and &lt;code>.unlink()&lt;/code> respectively.&lt;/p>
&lt;h2 id="listing-files">Listing files&lt;/h2>
&lt;ul>
&lt;li>&lt;code>Path.iterdir()&lt;/code> : iterates over all files in the given directory&lt;/li>
&lt;li>More flexible file listing
&lt;ul>
&lt;li>&lt;code>Path.glob()&lt;/code>&lt;/li>
&lt;li>&lt;code>Path.rglob()&lt;/code> (recursive glob)&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h2 id="moving-files">Moving files&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">Path&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">current_location&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">rename&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">new_location&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="correspondence-to-tools-in-the-oshttpsdocspythonorg3libraryoshtmlmodule-os-module">Correspondence to tools in the &lt;a href="https://docs.python.org/3/library/os.html#module-os">&lt;code>os&lt;/code>&lt;/a> module&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:left">os and os.path&lt;/th>
&lt;th style="text-align:left">pathlib&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.abspath">&lt;code>os.path.abspath()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve">&lt;code>Path.resolve()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.chmod">&lt;code>os.chmod()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.chmod">&lt;code>Path.chmod()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.mkdir">&lt;code>os.mkdir()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir">&lt;code>Path.mkdir()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.makedirs">&lt;code>os.makedirs()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir">&lt;code>Path.mkdir(parents=True)&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.rename">&lt;code>os.rename()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.rename">&lt;code>Path.rename()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.replace">&lt;code>os.replace()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.replace">&lt;code>Path.replace()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.rmdir">&lt;code>os.rmdir()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.rmdir">&lt;code>Path.rmdir()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.remove">&lt;code>os.remove()&lt;/code>&lt;/a>, &lt;a href="https://docs.python.org/3/library/os.html#os.unlink">&lt;code>os.unlink()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.unlink">&lt;code>Path.unlink()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.getcwd">&lt;code>os.getcwd()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.cwd">&lt;code>Path.cwd()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.exists">&lt;code>os.path.exists()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.exists">&lt;code>Path.exists()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.expanduser">&lt;code>os.path.expanduser()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.expanduser">&lt;code>Path.expanduser()&lt;/code>&lt;/a> and &lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.home">&lt;code>Path.home()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.listdir">&lt;code>os.listdir()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.iterdir">&lt;code>Path.iterdir()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.isdir">&lt;code>os.path.isdir()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_dir">&lt;code>Path.is_dir()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.isfile">&lt;code>os.path.isfile()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_file">&lt;code>Path.is_file()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.islink">&lt;code>os.path.islink()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_symlink">&lt;code>Path.is_symlink()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.link">&lt;code>os.link()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.link_to">&lt;code>Path.link_to()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.symlink">&lt;code>os.symlink()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.symlink_to">&lt;code>Path.symlink_to()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.readlink">&lt;code>os.readlink()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.readlink">&lt;code>Path.readlink()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.html#os.stat">&lt;code>os.stat()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat">&lt;code>Path.stat()&lt;/code>&lt;/a>, &lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.owner">&lt;code>Path.owner()&lt;/code>&lt;/a>, &lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.group">&lt;code>Path.group()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.isabs">&lt;code>os.path.isabs()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.is_absolute">&lt;code>PurePath.is_absolute()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.join">&lt;code>os.path.join()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.joinpath">&lt;code>PurePath.joinpath()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.basename">&lt;code>os.path.basename()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.name">&lt;code>PurePath.name&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.dirname">&lt;code>os.path.dirname()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.parent">&lt;code>PurePath.parent&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.samefile">&lt;code>os.path.samefile()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.Path.samefile">&lt;code>Path.samefile()&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/os.path.html#os.path.splitext">&lt;code>os.path.splitext()&lt;/code>&lt;/a>&lt;/td>
&lt;td style="text-align:left">&lt;a href="https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.suffix">&lt;code>PurePath.suffix&lt;/code>&lt;/a>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="pathlib-cheatsheet">&lt;code>pathlib&lt;/code> cheatsheet&lt;/h2>
&lt;p>&lt;a href="https://github.com/chris1610/pbpython/blob/master/extras/Pathlib-Cheatsheet.pdf">pathlib cheatsheet&lt;/a>&lt;/p>
&lt;h2 id="google-colab-notebook">Google Colab Notebook&lt;/h2>
&lt;p>Open in &lt;a href="https://colab.research.google.com/drive/1jKTOzkIFs1ZSyp3xUXugR1C1-5Lv9mPZ#scrollTo=U-MJKEzD1TeG">Colab&lt;/a>&lt;/p>
&lt;h2 id="reference">Reference&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Documentation: &lt;a href="https://docs.python.org/3/library/pathlib.html#module-pathlib">&lt;code>pathlib&lt;/code>&lt;/a> — Object-oriented filesystem paths&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://realpython.com/python-pathlib/#the-problem-with-python-file-path-handling">Python 3&amp;rsquo;s pathlib Module: Taming the File System&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul></description></item></channel></rss>