|
1395 | 1395 |
|
1396 | 1396 |
|
1397 | 1397 | <ul>
|
1398 |
| -<li><strong><code class="python hljs"><span class="hljs-string">'encoding=None'</span></code> means default encoding is used, which is platform dependent. Best practice is to use <code class="python hljs"><span class="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li> |
| 1398 | +<li><strong><code class="python hljs"><span class="hljs-string">'encoding=None'</span></code> means that the default encoding is used, which is platform dependent. Best practice is to use <code class="python hljs"><span class="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li> |
1399 | 1399 | <li><strong><code class="python hljs"><span class="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.</strong></li>
|
1400 | 1400 | <li><strong><code class="python hljs"><span class="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.</strong></li>
|
1401 | 1401 | </ul>
|
|
1430 | 1430 | <str/bytes> = next(<file>) <span class="hljs-comment"># Returns a line using buffer. Do not mix.</span>
|
1431 | 1431 | </code></pre>
|
1432 | 1432 | <pre><code class="python language-python hljs"><file>.write(<str/bytes>) <span class="hljs-comment"># Writes a string or bytes object.</span>
|
1433 |
| -<file>.writelines(<coll.>) <span class="hljs-comment"># Writes a coll. of strings or bytes objects.</span> |
| 1433 | +<file>.writelines(<collection>) <span class="hljs-comment"># Writes a coll. of strings or bytes objects.</span> |
1434 | 1434 | <file>.flush() <span class="hljs-comment"># Flushes write buffer.</span>
|
1435 | 1435 | </code></pre>
|
1436 | 1436 | <ul>
|
|
1446 | 1446 | file.write(text)
|
1447 | 1447 | </code></pre></div>
|
1448 | 1448 |
|
1449 |
| -<div><h2 id="path"><a href="#path" name="path">#</a>Path</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> path, listdir |
| 1449 | +<div><h2 id="path"><a href="#path" name="path">#</a>Path</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> getcwd, path, listdir |
1450 | 1450 | <span class="hljs-keyword">from</span> glob <span class="hljs-keyword">import</span> glob
|
1451 | 1451 | </code></pre></div>
|
1452 | 1452 |
|
| 1453 | +<pre><code class="python language-python hljs"><str> = getcwd() <span class="hljs-comment"># Returns the current working directory.</span> |
| 1454 | +</code></pre> |
1453 | 1455 | <pre><code class="python language-python hljs"><bool> = path.exists(<span class="hljs-string">'<path>'</span>)
|
1454 | 1456 | <bool> = path.isfile(<span class="hljs-string">'<path>'</span>)
|
1455 | 1457 | <bool> = path.isdir(<span class="hljs-string">'<path>'</span>)
|
|
1492 | 1494 | <pre><code class="python language-python hljs">os.chdir(<path>) <span class="hljs-comment"># Changes current working directory.</span>
|
1493 | 1495 | os.mkdir(<path>, mode=<span class="hljs-number">0o777</span>) <span class="hljs-comment"># Creates a directory.</span>
|
1494 | 1496 | </code></pre>
|
| 1497 | +<pre><code class="python language-python hljs">shutil.copy(from, to) <span class="hljs-comment"># Copies the file.</span> |
| 1498 | +shutil.copytree(from, to) <span class="hljs-comment"># Copies the entire directory tree.</span> |
| 1499 | +</code></pre> |
1495 | 1500 | <pre><code class="python language-python hljs">os.rename(from, to) <span class="hljs-comment"># Renames the file or directory.</span>
|
1496 | 1501 | os.replace(from, to) <span class="hljs-comment"># Same, but overwrites 'to' if it exists.</span>
|
1497 | 1502 | </code></pre>
|
1498 | 1503 | <pre><code class="python language-python hljs">os.remove(<path>) <span class="hljs-comment"># Deletes the file.</span>
|
1499 | 1504 | os.rmdir(<path>) <span class="hljs-comment"># Deletes empty directory.</span>
|
1500 | 1505 | shutil.rmtree(<path>) <span class="hljs-comment"># Deletes the entire directory tree.</span>
|
1501 | 1506 | </code></pre>
|
1502 |
| -<pre><code class="python language-python hljs">shutil.copy(from, to) <span class="hljs-comment"># Copies the file.</span> |
1503 |
| -shutil.copytree(from, to) <span class="hljs-comment"># Copies the entire directory tree.</span> |
1504 |
| -</code></pre> |
1505 |
| -<pre><code class="python language-python hljs"><str> = os.getcwd() <span class="hljs-comment"># Returns the current working directory.</span> |
1506 |
| -<iter> = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns os.DirEntry objects located at path.</span> |
| 1507 | +<pre><code class="python language-python hljs"><iter> = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns os.DirEntry objects located at path.</span> |
1507 | 1508 | </code></pre>
|
1508 | 1509 | <div><h4 id="direntry">DirEntry:</h4><pre><code class="python language-python hljs"><bool> = <DirEntry>.is_file()
|
1509 | 1510 | <bool> = <DirEntry>.is_dir()
|
|
0 commit comments