|
56 | 56 |
|
57 | 57 | <body> |
58 | 58 | <header> |
59 | | - <aside>June 21, 2025</aside> |
| 59 | + <aside>July 19, 2025</aside> |
60 | 60 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
61 | 61 | </header> |
62 | 62 |
|
63 | | - <div class="pagebreak"></div> |
64 | | -<div><h1 id="comprehensivepythoncheatsheet">Comprehensive Python Cheatsheet</h1><p class="banner"><sup><a href="https://raw.githubusercontent.com/gto76/python-cheatsheet/main/README.md">Download text file</a>, <a href="https://github.com/gto76/python-cheatsheet">Fork me on GitHub</a>, <a href="https://github.com/gto76/python-cheatsheet/wiki/Frequently-Asked-Questions">Check out FAQ</a> or <a href="index.html?theme=dark3">Switch to dark theme</a>. |
| 63 | + <div><h1 id="comprehensivepythoncheatsheet">Comprehensive Python Cheatsheet</h1><p class="banner"><sup><a href="https://raw.githubusercontent.com/gto76/python-cheatsheet/main/README.md">Download text file</a>, <a href="https://github.com/gto76/python-cheatsheet">Fork me on GitHub</a>, <a href="https://github.com/gto76/python-cheatsheet/wiki/Frequently-Asked-Questions">Check out FAQ</a> or <a href="index.html?theme=dark3">Switch to dark theme</a>. |
65 | 64 | </sup></p><p class="banner" style="margin-bottom: 20px; padding-bottom: 7px;"><img src="web/image_888.jpeg" alt="Monty Python"></p><script> |
66 | 65 | // Changes the banner image and link-to-theme if "theme=dark" is in query string |
67 | 66 | // or if browser prefers dark mode and theme is not explicitly set. |
|
594 | 593 | <TD> = <DTa> - <DTa> <span class="hljs-comment"># Ignores jumps if they share tzinfo object.</span> |
595 | 594 | <D/DT> = <D/DT> ± <TD> <span class="hljs-comment"># Returned datetime can fall into missing hour.</span> |
596 | 595 | <TD> = <TD> * <float> <span class="hljs-comment"># Also `<TD> = abs(<TD>)`, `<TD> = <TD> ± <TD>`.</span> |
| 596 | +<float> = <TD> / <TD> <span class="hljs-comment"># Also `(<int>, <TD>) = divmod(<TD>, <TD>)`.</span> |
597 | 597 | </code></pre></div> |
598 | 598 |
|
599 | 599 | <div><h2 id="function"><a href="#function" name="function">#</a>Function</h2><p><strong>Independent block of code that returns a value when called.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <<span class="hljs-title">func_name</span>><span class="hljs-params">(<nondefault_args>)</span>:</span> ... <span class="hljs-comment"># E.g. `def func(x, y): ...`.</span> |
|
1568 | 1568 | <div><h3 id="writerowstocsvfile">Write Rows to CSV File</h3><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">write_to_csv_file</span><span class="hljs-params">(filename, rows, mode=<span class="hljs-string">'w'</span>, **csv_params)</span>:</span> |
1569 | 1569 | <span class="hljs-keyword">with</span> open(filename, mode, encoding=<span class="hljs-string">'utf-8'</span>, newline=<span class="hljs-string">''</span>) <span class="hljs-keyword">as</span> file: |
1570 | 1570 | writer = csv.writer(file, **csv_params) |
| 1571 | + writer.writerows(rows) |
1571 | 1572 | </code></pre></div> |
1572 | 1573 |
|
1573 | 1574 | <div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>A server-less database engine that stores each database into its own file.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3 |
@@ -1973,6 +1974,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
1973 | 1974 | curses.wrapper(main) |
1974 | 1975 | </code></pre></div> |
1975 | 1976 |
|
| 1977 | +<p><br></p> |
1976 | 1978 | <div><h1 id="libraries">Libraries</h1><div><h2 id="progressbar"><a href="#progressbar" name="progressbar">#</a>Progress Bar</h2><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install tqdm</span> |
1977 | 1979 | <span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> tqdm, time |
1978 | 1980 | <span class="hljs-meta">>>> </span><span class="hljs-keyword">for</span> el <span class="hljs-keyword">in</span> tqdm.tqdm([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], desc=<span class="hljs-string">'Processing'</span>): |
@@ -2936,7 +2938,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2936 | 2938 |
|
2937 | 2939 |
|
2938 | 2940 | <footer> |
2939 | | - <aside>June 21, 2025</aside> |
| 2941 | + <aside>July 19, 2025</aside> |
2940 | 2942 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2941 | 2943 | </footer> |
2942 | 2944 |
|
|
0 commit comments