|
54 | 54 |
|
55 | 55 | <body>
|
56 | 56 | <header>
|
57 |
| - <aside>April 20, 2022</aside> |
| 57 | + <aside>May 2, 2022</aside> |
58 | 58 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
59 | 59 | </header>
|
60 | 60 |
|
|
585 | 585 | <TD> = <D/DTn> - <D/DTn> <span class="hljs-comment"># Returns the difference, ignoring time jumps.</span>
|
586 | 586 | <TD> = <DTa> - <DTa> <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span>
|
587 | 587 | <TD> = <TD> * <real> <span class="hljs-comment"># Also: <TD> = abs(<TD>) and <TD> = <TD> ±% <TD>.</span>
|
588 |
| -<float> = <TD> / <TD> <span class="hljs-comment"># How many weeks/years there are in TD. Also '//'.</span> |
| 588 | +<float> = <TD> / <TD> <span class="hljs-comment"># How many weeks/years there are in TD. Also //.</span> |
589 | 589 | </code></pre></div>
|
590 | 590 |
|
591 | 591 | <div><h2 id="arguments"><a href="#arguments" name="arguments">#</a>Arguments</h2><div><h3 id="insidefunctioncall">Inside Function Call</h3><pre><code class="python language-python hljs"><function>(<positional_args>) <span class="hljs-comment"># f(0, 0)</span>
|
|
1392 | 1392 | <bool> = path.isfile(<path>) <span class="hljs-comment"># Or: <DirEntry/Path>.is_file()</span>
|
1393 | 1393 | <bool> = path.isdir(<path>) <span class="hljs-comment"># Or: <DirEntry/Path>.is_dir()</span>
|
1394 | 1394 | </code></pre>
|
| 1395 | +<pre><code class="python language-python hljs"><stat> = os.stat(<path>) <span class="hljs-comment"># Or: <DirEntry/Path>.stat()</span> |
| 1396 | +<real> = <stat>.st_mtime/st_size/… <span class="hljs-comment"># Modification time, size in bytes, …</span> |
| 1397 | +</code></pre> |
1395 | 1398 | <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"><iter> = scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns DirEntry objects located at path.</span>
|
1396 | 1399 | <str> = <DirEntry>.path <span class="hljs-comment"># Returns whole path as a string.</span>
|
1397 | 1400 | <str> = <DirEntry>.name <span class="hljs-comment"># Returns final component as a string.</span>
|
|
1503 | 1506 | </code></pre></div>
|
1504 | 1507 |
|
1505 | 1508 | <ul>
|
| 1509 | +<li><strong>For XML and binary Excel files (xlsx, xlsm and xlsb) use <a href="#dataframeplotencodedecode">Pandas</a> library.</strong></li> |
1506 | 1510 | <li><strong>File must be opened with a <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or newlines embedded inside quoted fields will not be interpreted correctly!</strong></li>
|
1507 | 1511 | </ul>
|
1508 | 1512 | <div><h3 id="write">Write</h3><pre><code class="python language-python hljs"><writer> = csv.writer(<file>) <span class="hljs-comment"># Also: `dialect='excel', delimiter=','`.</span>
|
|
1879 | 1883 | <li><strong>Coroutine definition starts with <code class="python hljs"><span class="hljs-string">'async'</span></code> and its call with <code class="python hljs"><span class="hljs-string">'await'</span></code>.</strong></li>
|
1880 | 1884 | <li><strong><code class="python hljs"><span class="hljs-string">'asyncio.run(<coroutine>)'</span></code> is the main entry point for asynchronous programs.</strong></li>
|
1881 | 1885 | <li><strong>Functions wait(), gather() and as_completed() can be used when multiple coroutines need to be started at the same time.</strong></li>
|
1882 |
| -<li><strong>Asyncio module also provides its own <a href="#queue">Queue</a>, <a href="#semaphoreeventbarrier">Event</a>, <a href="#lock">Lock</a> and <a href="#semaphore-event-barrier">Semaphore</a> classes.</strong></li> |
| 1886 | +<li><strong>Asyncio module also provides its own <a href="#queue">Queue</a>, <a href="#semaphoreeventbarrier">Event</a>, <a href="#lock">Lock</a> and <a href="#semaphoreeventbarrier">Semaphore</a> classes.</strong></li> |
1883 | 1887 | </ul><div><h4 id="runsaterminalgamewhereyoucontrolanasteriskthatmustavoidnumbers">Runs a terminal game where you control an asterisk that must avoid numbers:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> asyncio, collections, curses, curses.textpad, enum, random
|
1884 | 1888 |
|
1885 | 1889 | P = collections.namedtuple(<span class="hljs-string">'P'</span>, <span class="hljs-string">'x y'</span>) <span class="hljs-comment"># Position</span>
|
|
2887 | 2891 |
|
2888 | 2892 |
|
2889 | 2893 | <footer>
|
2890 |
| - <aside>April 20, 2022</aside> |
| 2894 | + <aside>May 2, 2022</aside> |
2891 | 2895 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
2892 | 2896 | </footer>
|
2893 | 2897 |
|
|
0 commit comments