|
55 | 55 |
|
56 | 56 | <body> |
57 | 57 | <header> |
58 | | - <aside>October 25, 2024</aside> |
| 58 | + <aside>October 26, 2024</aside> |
59 | 59 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
60 | 60 | </header> |
61 | 61 |
|
@@ -1877,22 +1877,22 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
1877 | 1877 | 2023-02-07 23:21:01,430 CRITICAL:my_module:Running out of disk space. |
1878 | 1878 | </code></pre></div> |
1879 | 1879 |
|
1880 | | -<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs"><list> = dir() <span class="hljs-comment"># Names of local vars, functions, classes and modules.</span> |
1881 | | -<dict> = vars() <span class="hljs-comment"># Dict of local vars, functions, etc. Also locals().</span> |
1882 | | -<dict> = globals() <span class="hljs-comment"># Dict of global vars, etc. (including '__builtins__').</span> |
| 1880 | +<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs"><list> = dir() <span class="hljs-comment"># List of of local names (including functions and classes).</span> |
| 1881 | +<dict> = vars() <span class="hljs-comment"># Dict of local names and their objects. Also locals().</span> |
| 1882 | +<dict> = globals() <span class="hljs-comment"># Dict of global names (for instance '__builtin__' module).</span> |
1883 | 1883 | </code></pre></div> |
1884 | 1884 |
|
1885 | | -<pre><code class="python language-python hljs"><list> = dir(<obj>) <span class="hljs-comment"># Names of all object's attributes (including methods).</span> |
1886 | | -<dict> = vars(<obj>) <span class="hljs-comment"># Dict of writable attributes. Also <obj>.__dict__.</span> |
1887 | | -<bool> = hasattr(<obj>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Checks if getattr() raises AttributeError.</span> |
1888 | | -value = getattr(<obj>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Default value can be passed as the third argument.</span> |
1889 | | -setattr(<obj>, <span class="hljs-string">'<attr_name>'</span>, value) <span class="hljs-comment"># Only works on objects with __dict__ attribute.</span> |
1890 | | -delattr(<obj>, <span class="hljs-string">'<attr_name>'</span>) <span class="hljs-comment"># Same. Also `del <object>.<attr_name>`.</span> |
| 1885 | +<pre><code class="python language-python hljs"><list> = dir(<obj>) <span class="hljs-comment"># Returns names of all object's attributes (incl. methods).</span> |
| 1886 | +<dict> = vars(<obj>) <span class="hljs-comment"># Returns dict of writable attributes. Also <obj>.__dict__.</span> |
| 1887 | +<bool> = hasattr(<obj>, <span class="hljs-string">'<name>'</span>) <span class="hljs-comment"># Checks if object possesses attribute with passed name.</span> |
| 1888 | +value = getattr(<obj>, <span class="hljs-string">'<name>'</span>) <span class="hljs-comment"># Returns object's attribute or raises AttributeError.</span> |
| 1889 | +setattr(<obj>, <span class="hljs-string">'<name>'</span>, value) <span class="hljs-comment"># Sets attribute. Only works on objects with __dict__.</span> |
| 1890 | +delattr(<obj>, <span class="hljs-string">'<name>'</span>) <span class="hljs-comment"># Deletes attribute from __dict__. Also `del <obj>.<name>`.</span> |
1891 | 1891 | </code></pre> |
1892 | | -<pre><code class="python language-python hljs"><Sig> = inspect.signature(<function>) <span class="hljs-comment"># Returns function's Signature object.</span> |
1893 | | -<dict> = <Sig>.parameters <span class="hljs-comment"># Dict of Parameters. Also <Sig>.return_annotation.</span> |
1894 | | -<memb> = <Param>.kind <span class="hljs-comment"># Member of ParamKind enum (Parameter.KEYWORD_ONLY, …).</span> |
1895 | | -<obj> = <Param>.default <span class="hljs-comment"># Parameter.empty if missing. Also <Param>.annotation.</span> |
| 1892 | +<pre><code class="python language-python hljs"><Sig> = inspect.signature(<func>) <span class="hljs-comment"># Returns function's Signature object. Can accept a class.</span> |
| 1893 | +<dict> = <Sig>.parameters <span class="hljs-comment"># Returns dict of Parameters. Also <Sig>.return_annotation.</span> |
| 1894 | +<memb> = <Param>.kind <span class="hljs-comment"># Returns ParameterKind member (Parameter.KEYWORD_ONLY, …).</span> |
| 1895 | +<type> = <Param>.annotation <span class="hljs-comment"># Returns Parameter.empty if missing. Also <Param>.default.</span> |
1896 | 1896 | </code></pre> |
1897 | 1897 | <div><h2 id="coroutines"><a href="#coroutines" name="coroutines">#</a>Coroutines</h2><ul> |
1898 | 1898 | <li><strong>Coroutines have a lot in common with threads, but unlike threads, they only give up control when they call another coroutine and they don’t use as much memory.</strong></li> |
@@ -2927,7 +2927,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2927 | 2927 |
|
2928 | 2928 |
|
2929 | 2929 | <footer> |
2930 | | - <aside>October 25, 2024</aside> |
| 2930 | + <aside>October 26, 2024</aside> |
2931 | 2931 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2932 | 2932 | </footer> |
2933 | 2933 |
|
|
0 commit comments