| 
1457 | 1457 | <span class="hljs-keyword">from</span> glob <span class="hljs-keyword">import</span> glob  | 
1458 | 1458 | </code></pre></div>  | 
1459 | 1459 | 
 
  | 
1460 |  | -<pre><code class="python language-python hljs"><str>  = getcwd()                   <span class="hljs-comment"># Returns the current working directory.</span>  | 
 | 1460 | +<pre><code class="python language-python hljs"><str>  = getcwd()                   <span class="hljs-comment"># Returns current working directory.</span>  | 
1461 | 1461 | <str>  = path.join(<path>, ...)     <span class="hljs-comment"># Joins two or more pathname components.</span>  | 
1462 |  | -<str>  = path.abspath(<path>)       <span class="hljs-comment"># Returns an absolute path.</span>  | 
 | 1462 | +<str>  = path.abspath(<path>)       <span class="hljs-comment"># Returns absolute path.</span>  | 
1463 | 1463 | </code></pre>  | 
1464 |  | -<pre><code class="python language-python hljs"><str>  = path.basename(<path>)      <span class="hljs-comment"># Returns final component.</span>  | 
1465 |  | -<str>  = path.dirname(<path>)       <span class="hljs-comment"># Returns path without final component.</span>  | 
1466 |  | -<tup.> = path.splitext(<path>)      <span class="hljs-comment"># Splits on last period of final component.</span>  | 
 | 1464 | +<pre><code class="python language-python hljs"><str>  = path.basename(<path>)      <span class="hljs-comment"># Returns final component of the path.</span>  | 
 | 1465 | +<str>  = path.dirname(<path>)       <span class="hljs-comment"># Returns path without the final component.</span>  | 
 | 1466 | +<tup.> = path.splitext(<path>)      <span class="hljs-comment"># Splits on last period of the final component.</span>  | 
1467 | 1467 | </code></pre>  | 
1468 | 1468 | <pre><code class="python language-python hljs"><list> = listdir(path=<span class="hljs-string">'.'</span>)          <span class="hljs-comment"># Returns filenames located at path.</span>  | 
1469 | 1469 | <list> = glob(<span class="hljs-string">'<pattern>'</span>)          <span class="hljs-comment"># Returns paths matching the wildcard pattern.</span>  | 
 | 
1479 | 1479 | <pre><code class="python language-python hljs"><iter> = scandir(path=<span class="hljs-string">'.'</span>)          <span class="hljs-comment"># Returns DirEntry objects located at path.</span>  | 
1480 | 1480 | <str>  = <DirEntry>.path            <span class="hljs-comment"># Returns path as a string.</span>  | 
1481 | 1481 | <str>  = <DirEntry>.name            <span class="hljs-comment"># Returns final component as a string.</span>  | 
1482 |  | -<file> = open(<DirEntry>)           <span class="hljs-comment"># Opens the file and returns a file object.</span>  | 
 | 1482 | +<file> = open(<DirEntry>)           <span class="hljs-comment"># Opens the file and returns file object.</span>  | 
1483 | 1483 | </code></pre>  | 
1484 | 1484 | <div><h3 id="pathobject">Path Object</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path  | 
1485 | 1485 | </code></pre></div>  | 
 | 
1501 | 1501 | <iter> = <Path>.glob(<span class="hljs-string">'<pattern>'</span>)   <span class="hljs-comment"># Returns Paths matching the wildcard pattern.</span>  | 
1502 | 1502 | </code></pre>  | 
1503 | 1503 | <pre><code class="python language-python hljs"><str>  = str(<Path>)                <span class="hljs-comment"># Returns path as a string.</span>  | 
1504 |  | -<file> = open(<Path>)               <span class="hljs-comment"># Opens the file and returns a file object.</span>  | 
 | 1504 | +<file> = open(<Path>)               <span class="hljs-comment"># Opens the file and returns file object.</span>  | 
1505 | 1505 | </code></pre>  | 
1506 | 1506 | <div><h2 id="oscommands"><a href="#oscommands" name="oscommands">#</a>OS Commands</h2><div><h3 id="filesanddirectories">Files and Directories</h3><ul>  | 
1507 | 1507 | <li><strong>Paths can be either strings, Paths, or DirEntry objects.</strong></li>  | 
 | 
1511 | 1511 | 
 
  | 
1512 | 1512 | 
 
  | 
1513 | 1513 | 
 
  | 
1514 |  | -<pre><code class="python language-python hljs">os.chdir(<path>)                    <span class="hljs-comment"># Changes the current working directory.</span>  | 
 | 1514 | +<pre><code class="python language-python hljs">os.chdir(<path>)                    <span class="hljs-comment"># Changes current working directory.</span>  | 
1515 | 1515 | os.mkdir(<path>, mode=<span class="hljs-number">0o777</span>)        <span class="hljs-comment"># Creates a directory. Mode is in octal.</span>  | 
1516 | 1516 | </code></pre>  | 
1517 | 1517 | <pre><code class="python language-python hljs">shutil.copy(from, to)               <span class="hljs-comment"># Copies the file.</span>  | 
 | 
0 commit comments