title: Pathlib vs. os.path.join in Python
body: <p>When I need to define a file system path in my script, I use <code>os.path.join</code> to guarantee that the path will be consistent on different file systems:</p>
  <pre><code>from os import path
  path_1 = path.join(&quot;home&quot;, &quot;test&quot;, &quot;test.txt&quot;)
  </code></pre>
  <p>I also know that there is <code>Pathlib</code> library that basically does the same:</p>
  <pre><code>from pathlib import Path
  path_2 = Path(&quot;home&quot;) / &quot;test&quot; / &quot;test.txt&quot;
  </code></pre>
  <p>What is the difference between these two ways to handle paths? Which one is better?</p>