* **Partial is also useful in cases when function needs to be passed as an argument because it enables us to set its arguments beforehand.**
* **Partial is also useful in cases when a function needs to be passed as an argument because it enables us to set its arguments beforehand.**
* **A few examples being: `'defaultdict(<func>)'`, `'iter(<func>, to_exc)'` and dataclass's `'field(default_factory=<func>)'`.**
### Non-Local
@ -1664,7 +1664,7 @@ from pathlib import Path
```
### DirEntry
**Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir and on Windows also stat information, thus significantly increasing the performance of code that requires it.**
**Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir, and on Windows also stat information, thus significantly increasing the performance of code that requires it.**
```python
<iter> = os.scandir(path='.') # Returns DirEntry objects located at the path.
@ -2275,7 +2275,7 @@ log.basicConfig(
* **RotatingFileHandler creates and deletes files based on 'maxBytes', 'backupCount' args.**
* **An object with `'filter(<LogRecord>)'` method (or the method itself) can be added to loggers and handlers via addFilter(). Message is dropped if filter() returns a false value.**
#### Creates a logger that writes all messages to file and sends them to the root's handler that prints warnings or higher:
#### Creates a logger that writes all messages to a file and sends them to the root's handler that prints warnings or higher:
@ -725,7 +725,7 @@ player = Player(point, direction) <span class="hljs-comment">#
<spanclass="hljs-number">30</span>
</code></pre>
<ul>
<li><strong>Partial is also useful in cases when function needs to be passed as an argument because it enables us to set its arguments beforehand.</strong></li>
<li><strong>Partial is also useful in cases when a function needs to be passed as an argument because it enables us to set its arguments beforehand.</strong></li>
<li><strong>A few examples being: <codeclass="python hljs"><spanclass="hljs-string">'defaultdict(<func>)'</span></code>, <codeclass="python hljs"><spanclass="hljs-string">'iter(<func>, to_exc)'</span></code> and dataclass's <codeclass="python hljs"><spanclass="hljs-string">'field(default_factory=<func>)'</span></code>.</strong></li>
</ul>
<div><h3id="nonlocal">Non-Local</h3><p><strong>If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-function"><spanclass="hljs-keyword">def</span><spanclass="hljs-title">get_counter</span><spanclass="hljs-params">()</span>:</span>
<num> = <stat>.st_mtime/st_size/… <spanclass="hljs-comment"># Modification time, size in bytes, ...</span>
</code></pre>
<div><h3id="direntry">DirEntry</h3><p><strong>Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir and on Windows also stat information, thus significantly increasing the performance of code that requires it.</strong></p><pre><codeclass="python language-python hljs"><iter> = os.scandir(path=<spanclass="hljs-string">'.'</span>) <spanclass="hljs-comment"># Returns DirEntry objects located at the path.</span>
<div><h3id="direntry">DirEntry</h3><p><strong>Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir, and on Windows also stat information, thus significantly increasing the performance of code that requires it.</strong></p><pre><codeclass="python language-python hljs"><iter> = os.scandir(path=<spanclass="hljs-string">'.'</span>) <spanclass="hljs-comment"># Returns DirEntry objects located at the path.</span>
<str> = <DirEntry>.path <spanclass="hljs-comment"># Returns the whole path as a string.</span>
<str> = <DirEntry>.name <spanclass="hljs-comment"># Returns final component as a string.</span>
<file> = open(<DirEntry>) <spanclass="hljs-comment"># Opens the file and returns a file object.</span>
<li><strong>RotatingFileHandler creates and deletes files based on 'maxBytes', 'backupCount' args.</strong></li>
<li><strong>An object with <codeclass="python hljs"><spanclass="hljs-string">'filter(<LogRecord>)'</span></code> method (or the method itself) can be added to loggers and handlers via addFilter(). Message is dropped if filter() returns a false value.</strong></li>
</ul>
<div><h4id="createsaloggerthatwritesallmessagestofileandsendsthemtotherootshandlerthatprintswarningsorhigher">Creates a logger that writes all messages to file and sends them to the root's handler that prints warnings or higher:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>logger = log.getLogger(<spanclass="hljs-string">'my_module'</span>)
<div><h4id="createsaloggerthatwritesallmessagestoafileandsendsthemtotherootshandlerthatprintswarningsorhigher">Creates a logger that writes all messages to a file and sends them to the root's handler that prints warnings or higher:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>logger = log.getLogger(<spanclass="hljs-string">'my_module'</span>)