|
226 | 226 |
|
227 | 227 | <body>
|
228 | 228 | <header>
|
229 |
| - <aside>October 16, 2021</aside> |
| 229 | + <aside>October 20, 2021</aside> |
230 | 230 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
231 | 231 | </header>
|
232 | 232 |
|
|
412 | 412 | <pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>type(<span class="hljs-string">'a'</span>), <span class="hljs-string">'a'</span>.__class__, str
|
413 | 413 | (<<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">str</span>'>, <<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'>, <<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'>)
|
414 | 414 | </span></code></pre>
|
415 |
| -<div><h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have built-in names, so they must be imported:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> types <span class="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType |
| 415 | +<div><h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have built-in names, so they must be imported:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> types <span class="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType, ModuleType |
416 | 416 | </code></pre></div>
|
417 | 417 |
|
418 | 418 | <div><h3 id="abstractbaseclasses">Abstract Base Classes</h3><p><strong>Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Iterable ABC looks for method iter() while Collection ABC looks for methods iter(), contains() and len().</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Sequence, Collection, Iterable
|
|
1661 | 1661 | <li><strong><code class="python hljs"><span class="hljs-string">'skipinitialspace'</span></code> - Whether whitespace after delimiter gets stripped.</strong></li>
|
1662 | 1662 | <li><strong><code class="python hljs"><span class="hljs-string">'lineterminator'</span></code> - Specifies how writer terminates rows.</strong></li>
|
1663 | 1663 | <li><strong><code class="python hljs"><span class="hljs-string">'quoting'</span></code> - Controls the amount of quoting: 0 - as necessary, 1 - all.</strong></li>
|
1664 |
| -<li><strong><code class="python hljs"><span class="hljs-string">'escapechar'</span></code> - Character for escaping 'quotechar' if 'doublequote' is False.</strong></li> |
| 1664 | +<li><strong><code class="python hljs"><span class="hljs-string">'escapechar'</span></code> - Character for escaping quotechars if doublequote is False.</strong></li> |
1665 | 1665 | </ul><div><h3 id="dialects">Dialects</h3><pre><code class="text language-text">┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
|
1666 | 1666 | ┃ │ excel │ excel-tab │ unix ┃
|
1667 | 1667 | ┠──────────────────┼──────────────┼──────────────┼──────────────┨
|
|
1927 | 1927 | <dict> = vars(<object>) <span class="hljs-comment"># Dict of writable attributes. Also <obj>.__dict__.</span>
|
1928 | 1928 | <bool> = hasattr(<object>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Checks if getattr() raises an AttributeError.</span>
|
1929 | 1929 | value = getattr(<object>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Raises AttributeError if attribute is missing.</span>
|
1930 |
| -setattr(<object>, <span class="hljs-string">'<attr_name>'</span>, value) <span class="hljs-comment"># Only works on objects with __dict__ attribute.</span> |
1931 |
| -delattr(<object>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Equivalent to `del <object>.<attr_name>`.</span> |
| 1930 | +setattr(<object>, <span class="hljs-string">'<attr_name>'</span>, value) <span class="hljs-comment"># Only works on objects with '__dict__' attribute.</span> |
| 1931 | +delattr(<object>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Same. Also `del <object>.<attr_name>`.</span> |
1932 | 1932 | </code></pre></div>
|
1933 | 1933 |
|
1934 | 1934 | <div><h3 id="parameters-1">Parameters</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> inspect <span class="hljs-keyword">import</span> signature
|
|
1938 | 1938 | <memb> = <Param>.kind <span class="hljs-comment"># Member of ParameterKind enum.</span>
|
1939 | 1939 | </code></pre></div>
|
1940 | 1940 |
|
1941 |
| -<div><h2 id="metaprogramming"><a href="#metaprogramming" name="metaprogramming">#</a>Metaprogramming</h2><p><strong>Code that generates code.</strong></p><div><h3 id="type-1">Type</h3><p><strong>Type is the root class. If only passed an object it returns its type (class). Otherwise it creates a new class.</strong></p><pre><code class="python language-python hljs"><class> = type(<span class="hljs-string">'<class_name>'</span>, <parents_tuple>, <attributes_dict>)</code></pre></div></div> |
| 1941 | +<div><h2 id="metaprogramming"><a href="#metaprogramming" name="metaprogramming">#</a>Metaprogramming</h2><p><strong>Code that generates code.</strong></p><div><h3 id="type-1">Type</h3><p><strong>Type is the root class. If only passed an object it returns its type (class). Otherwise it creates a new class.</strong></p><pre><code class="python language-python hljs"><class> = type(<span class="hljs-string">'<class_name>'</span>, <tuple_of_parents>, <dict_of_class_attributes>)</code></pre></div></div> |
1942 | 1942 |
|
1943 | 1943 |
|
1944 | 1944 |
|
|
3017 | 3017 |
|
3018 | 3018 |
|
3019 | 3019 | <footer>
|
3020 |
| - <aside>October 16, 2021</aside> |
| 3020 | + <aside>October 20, 2021</aside> |
3021 | 3021 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
3022 | 3022 | </footer>
|
3023 | 3023 |
|
|
0 commit comments