Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5a6aa4

Browse files
committed
Path
1 parent dfdfbbf commit e5a6aa4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ def write_to_file(filename, text):
15621562
Path
15631563
----
15641564
```python
1565-
from os import getcwd, path, listdir, scandir
1565+
from os import getcwd, path, listdir
15661566
from glob import glob
15671567
```
15681568

@@ -1593,10 +1593,11 @@ from glob import glob
15931593
**Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type information.**
15941594

15951595
```python
1596-
<iter> = scandir(path='.') # Returns DirEntry objects located at path.
1596+
from os import scandir
15971597
```
15981598

15991599
```python
1600+
<iter> = scandir(path='.') # Returns DirEntry objects located at path.
16001601
<str> = <DirEntry>.path # Returns path as a string.
16011602
<str> = <DirEntry>.name # Returns final component as a string.
16021603
<file> = open(<DirEntry>) # Opens the file and returns a file object.

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@
14451445
file.write(text)
14461446
</code></pre></div>
14471447

1448-
<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, scandir
1448+
<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
14491449
<span class="hljs-keyword">from</span> glob <span class="hljs-keyword">import</span> glob
14501450
</code></pre></div>
14511451

@@ -1464,11 +1464,12 @@
14641464
&lt;bool&gt; = path.isfile(&lt;path&gt;) <span class="hljs-comment"># Or: &lt;DirEntry/Path&gt;.is_file()</span>
14651465
&lt;bool&gt; = path.isdir(&lt;path&gt;) <span class="hljs-comment"># Or: &lt;DirEntry/Path&gt;.is_dir()</span>
14661466
</code></pre>
1467-
<div><h3 id="direntry">DirEntry</h3><p><strong>Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type information.</strong></p><pre><code class="python language-python hljs">&lt;iter&gt; = scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns DirEntry objects located at path.</span>
1467+
<div><h3 id="direntry">DirEntry</h3><p><strong>Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type information.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> scandir
14681468
</code></pre></div>
14691469

14701470

1471-
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;DirEntry&gt;.path <span class="hljs-comment"># Returns path as a string.</span>
1471+
<pre><code class="python language-python hljs">&lt;iter&gt; = scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns DirEntry objects located at path.</span>
1472+
&lt;str&gt; = &lt;DirEntry&gt;.path <span class="hljs-comment"># Returns path as a string.</span>
14721473
&lt;str&gt; = &lt;DirEntry&gt;.name <span class="hljs-comment"># Returns final component as a string.</span>
14731474
&lt;file&gt; = open(&lt;DirEntry&gt;) <span class="hljs-comment"># Opens the file and returns a file object.</span>
14741475
</code></pre>

0 commit comments

Comments
 (0)