|
56 | 56 |
|
57 | 57 | <body> |
58 | 58 | <header> |
59 | | - <aside>December 5, 2025</aside> |
| 59 | + <aside>December 10, 2025</aside> |
60 | 60 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
61 | 61 | </header> |
62 | 62 |
|
|
713 | 713 | <li><strong>On a filesystem this corresponds to a directory of Python files with an optional init script.</strong></li> |
714 | 714 | <li><strong>Running <code class="python hljs"><span class="hljs-string">'import <package>'</span></code> does not automatically provide access to the package's modules unless they are explicitly imported in the <code class="python hljs"><span class="hljs-string">'<package>/__init__.py'</span></code> script.</strong></li> |
715 | 715 | <li><strong>Directory of the file that is passed to python command serves as a root of local imports.</strong></li> |
716 | | -<li><strong>For relative imports use <code class="python hljs"><span class="hljs-string">'from .[…][<pkg/module>[.…]] import <obj>'</span></code>.</strong></li> |
| 716 | +<li><strong>Use relative imports, i.e. <code class="python hljs"><span class="hljs-string">'from .[…][<pkg/mod>[.…]] import <obj>'</span></code>, if project has scattered entry points. Another option is to install the whole project by moving its code into 'src' dir, adding <a href="https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#basic-information">'pyproject.toml'</a> to its root, and running <code class="python hljs"><span class="hljs-string">'$ pip3 install -e .'</span></code>.</strong></li> |
717 | 717 | </ul> |
718 | | -<div><h2 id="closure"><a href="#closure" name="closure">#</a>Closure</h2><p><strong>We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns its nested function.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_multiplier</span><span class="hljs-params">(a)</span>:</span> |
| 718 | +<div><h2 id="closure"><a href="#closure" name="closure">#</a>Closure</h2><p><strong>We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns its nested function (any value that is referenced from within multiple nested functions gets shared).</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_multiplier</span><span class="hljs-params">(a)</span>:</span> |
719 | 719 | <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">out</span><span class="hljs-params">(b)</span>:</span> |
720 | 720 | <span class="hljs-keyword">return</span> a * b |
721 | 721 | <span class="hljs-keyword">return</span> out |
|
726 | 726 | <span class="hljs-meta">>>> </span>multiply_by_3(<span class="hljs-number">10</span>) |
727 | 727 | <span class="hljs-number">30</span> |
728 | 728 | </code></pre> |
729 | | -<ul> |
730 | | -<li><strong>Any value that is referenced from within multiple nested functions gets shared.</strong></li> |
731 | | -</ul> |
732 | 729 | <div><h3 id="partial">Partial</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial |
733 | 730 | <function> = partial(<function> [, <arg_1> [, ...]]) |
734 | 731 | </code></pre></div> |
|
1146 | 1143 |
|
1147 | 1144 | <ul> |
1148 | 1145 | <li><strong>Method iter() is required for <code class="python hljs"><span class="hljs-string">'isinstance(<obj>, abc.Iterable)'</span></code> to return True, however any object with getitem() will work with any code expecting an iterable.</strong></li> |
1149 | | -<li><strong>MutableSequence, Set, MutableSet, Mapping and MutableMapping ABCs are also extendable. Use <code class="python hljs"><span class="hljs-string">'<abc>.__abstractmethods__'</span></code> to get names of required methods.</strong></li> |
| 1146 | +<li><strong>MutableSequence, Set, MutableSet, Mapping and MutableMapping ABCs are also extendable. Use <code class="python hljs"><span class="hljs-string">'<abc>.__abstractmethods__'</span></code> to get names of required methods.</strong></li> |
1150 | 1147 | </ul> |
1151 | 1148 | <div><h2 id="enum"><a href="#enum" name="enum">#</a>Enum</h2><p><strong>Class of named constants called members.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum, auto |
1152 | 1149 | </code></pre></div> |
@@ -2938,7 +2935,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2938 | 2935 |
|
2939 | 2936 |
|
2940 | 2937 | <footer> |
2941 | | - <aside>December 5, 2025</aside> |
| 2938 | + <aside>December 10, 2025</aside> |
2942 | 2939 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2943 | 2940 | </footer> |
2944 | 2941 |
|
|
0 commit comments