Skip to content

Commit 848809d

Browse files
committed
Path
1 parent f42080c commit 848809d

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ Open
15051505
```python
15061506
<file> = open('<path>', mode='r', encoding=None, newline=None)
15071507
```
1508-
* **`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.**
1508+
* **`'encoding=None'` means that the default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.**
15091509
* **`'newline=None'` 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.**
15101510
* **`'newline=""'` means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.**
15111511

@@ -1543,7 +1543,7 @@ Open
15431543

15441544
```python
15451545
<file>.write(<str/bytes>) # Writes a string or bytes object.
1546-
<file>.writelines(<coll.>) # Writes a coll. of strings or bytes objects.
1546+
<file>.writelines(<collection>) # Writes a coll. of strings or bytes objects.
15471547
<file>.flush() # Flushes write buffer.
15481548
```
15491549
* **Methods do not add or strip trailing newlines, even writelines().**
@@ -1566,10 +1566,14 @@ def write_to_file(filename, text):
15661566
Path
15671567
----
15681568
```python
1569-
from os import path, listdir
1569+
from os import getcwd, path, listdir
15701570
from glob import glob
15711571
```
15721572

1573+
```python
1574+
<str> = getcwd() # Returns the current working directory.
1575+
```
1576+
15731577
```python
15741578
<bool> = path.exists('<path>')
15751579
<bool> = path.isfile('<path>')
@@ -1633,6 +1637,11 @@ os.chdir(<path>) # Changes current working directory.
16331637
os.mkdir(<path>, mode=0o777) # Creates a directory.
16341638
```
16351639

1640+
```python
1641+
shutil.copy(from, to) # Copies the file.
1642+
shutil.copytree(from, to) # Copies the entire directory tree.
1643+
```
1644+
16361645
```python
16371646
os.rename(from, to) # Renames the file or directory.
16381647
os.replace(from, to) # Same, but overwrites 'to' if it exists.
@@ -1645,12 +1654,6 @@ shutil.rmtree(<path>) # Deletes the entire directory tree.
16451654
```
16461655

16471656
```python
1648-
shutil.copy(from, to) # Copies the file.
1649-
shutil.copytree(from, to) # Copies the entire directory tree.
1650-
```
1651-
1652-
```python
1653-
<str> = os.getcwd() # Returns the current working directory.
16541657
<iter> = os.scandir(path='.') # Returns os.DirEntry objects located at path.
16551658
```
16561659

index.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@
13951395

13961396

13971397
<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>
13991399
<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>
14001400
<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>
14011401
</ul>
@@ -1430,7 +1430,7 @@
14301430
&lt;str/bytes&gt; = next(&lt;file&gt;) <span class="hljs-comment"># Returns a line using buffer. Do not mix.</span>
14311431
</code></pre>
14321432
<pre><code class="python language-python hljs">&lt;file&gt;.write(&lt;str/bytes&gt;) <span class="hljs-comment"># Writes a string or bytes object.</span>
1433-
&lt;file&gt;.writelines(&lt;coll.&gt;) <span class="hljs-comment"># Writes a coll. of strings or bytes objects.</span>
1433+
&lt;file&gt;.writelines(&lt;collection&gt;) <span class="hljs-comment"># Writes a coll. of strings or bytes objects.</span>
14341434
&lt;file&gt;.flush() <span class="hljs-comment"># Flushes write buffer.</span>
14351435
</code></pre>
14361436
<ul>
@@ -1446,10 +1446,12 @@
14461446
file.write(text)
14471447
</code></pre></div>
14481448

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
14501450
<span class="hljs-keyword">from</span> glob <span class="hljs-keyword">import</span> glob
14511451
</code></pre></div>
14521452

1453+
<pre><code class="python language-python hljs">&lt;str&gt; = getcwd() <span class="hljs-comment"># Returns the current working directory.</span>
1454+
</code></pre>
14531455
<pre><code class="python language-python hljs">&lt;bool&gt; = path.exists(<span class="hljs-string">'&lt;path&gt;'</span>)
14541456
&lt;bool&gt; = path.isfile(<span class="hljs-string">'&lt;path&gt;'</span>)
14551457
&lt;bool&gt; = path.isdir(<span class="hljs-string">'&lt;path&gt;'</span>)
@@ -1492,18 +1494,17 @@
14921494
<pre><code class="python language-python hljs">os.chdir(&lt;path&gt;) <span class="hljs-comment"># Changes current working directory.</span>
14931495
os.mkdir(&lt;path&gt;, mode=<span class="hljs-number">0o777</span>) <span class="hljs-comment"># Creates a directory.</span>
14941496
</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>
14951500
<pre><code class="python language-python hljs">os.rename(from, to) <span class="hljs-comment"># Renames the file or directory.</span>
14961501
os.replace(from, to) <span class="hljs-comment"># Same, but overwrites 'to' if it exists.</span>
14971502
</code></pre>
14981503
<pre><code class="python language-python hljs">os.remove(&lt;path&gt;) <span class="hljs-comment"># Deletes the file.</span>
14991504
os.rmdir(&lt;path&gt;) <span class="hljs-comment"># Deletes empty directory.</span>
15001505
shutil.rmtree(&lt;path&gt;) <span class="hljs-comment"># Deletes the entire directory tree.</span>
15011506
</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">&lt;str&gt; = os.getcwd() <span class="hljs-comment"># Returns the current working directory.</span>
1506-
&lt;iter&gt; = 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">&lt;iter&gt; = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns os.DirEntry objects located at path.</span>
15071508
</code></pre>
15081509
<div><h4 id="direntry">DirEntry:</h4><pre><code class="python language-python hljs">&lt;bool&gt; = &lt;DirEntry&gt;.is_file()
15091510
&lt;bool&gt; = &lt;DirEntry&gt;.is_dir()

0 commit comments

Comments
 (0)