|
496 | 496 | <span class="hljs-string">'187'</span>
|
497 | 497 | </code></pre></div>
|
498 | 498 |
|
499 |
| -<div><h3 id="generaloptions">General Options</h3><pre><code class="python language-python hljs">{<el>:<<span class="hljs-number">10</span>} <span class="hljs-comment"># '<el> '</span> |
500 |
| -{<el>:^<span class="hljs-number">10</span>} <span class="hljs-comment"># ' <el> '</span> |
501 |
| -{<el>:><span class="hljs-number">10</span>} <span class="hljs-comment"># ' <el>'</span> |
| 499 | +<div><h3 id="generaloptions">General Options</h3><pre><code class="python language-python hljs">{<el>:<<span class="hljs-number">10</span>} <span class="hljs-comment"># '<el> '</span> |
| 500 | +{<el>:^<span class="hljs-number">10</span>} <span class="hljs-comment"># ' <el> '</span> |
| 501 | +{<el>:><span class="hljs-number">10</span>} <span class="hljs-comment"># ' <el>'</span> |
502 | 502 | </code></pre></div>
|
503 | 503 |
|
504 |
| -<pre><code class="python language-python hljs">{<el>:.<<span class="hljs-number">10</span>} <span class="hljs-comment"># '<el>......'</span> |
505 |
| -{<el>:<<span class="hljs-number">0</span>} <span class="hljs-comment"># '<el>'</span> |
| 504 | +<pre><code class="python language-python hljs">{<el>:.<<span class="hljs-number">10</span>} <span class="hljs-comment"># '<el>......'</span> |
| 505 | +{<el>:<<span class="hljs-number">0</span>} <span class="hljs-comment"># '<el>'</span> |
506 | 506 | </code></pre>
|
507 |
| -<div><h3 id="strings">Strings</h3><p><strong><code class="python hljs"><span class="hljs-string">'!r'</span></code> calls object's repr() method, instead of str(), to get a string.</strong></p><pre><code class="python language-python hljs">{<span class="hljs-string">'abcde'</span>!r:<<span class="hljs-number">10</span>} <span class="hljs-comment"># "'abcde' "</span> |
508 |
| -{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">.3</span>} <span class="hljs-comment"># 'abc'</span> |
509 |
| -{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># 'abc '</span> |
| 507 | +<div><h3 id="strings">Strings</h3><p><strong><code class="python hljs"><span class="hljs-string">'!r'</span></code> calls object's repr() method, instead of str(), to get a string.</strong></p><pre><code class="python language-python hljs">{<span class="hljs-string">'abcde'</span>!r:<<span class="hljs-number">10</span>} <span class="hljs-comment"># "'abcde' "</span> |
| 508 | +{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">.3</span>} <span class="hljs-comment"># 'abc'</span> |
| 509 | +{<span class="hljs-string">'abcde'</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># 'abc '</span> |
510 | 510 | </code></pre></div>
|
511 | 511 |
|
512 | 512 |
|
513 |
| -<div><h3 id="numbers-1">Numbers</h3><pre><code class="python language-python hljs">{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>,} <span class="hljs-comment"># ' 123,456'</span> |
514 |
| -{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>_} <span class="hljs-comment"># ' 123_456'</span> |
515 |
| -{ <span class="hljs-number">123456</span>:+<span class="hljs-number">10</span>} <span class="hljs-comment"># ' +123456'</span> |
516 |
| -{<span class="hljs-number">-123456</span>:=<span class="hljs-number">10</span>} <span class="hljs-comment"># '- 123456'</span> |
517 |
| -{ <span class="hljs-number">123456</span>: } <span class="hljs-comment"># ' 123456'</span> |
518 |
| -{<span class="hljs-number">-123456</span>: } <span class="hljs-comment"># '-123456'</span> |
| 513 | +<div><h3 id="numbers-1">Numbers</h3><pre><code class="python language-python hljs">{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>,} <span class="hljs-comment"># ' 123,456'</span> |
| 514 | +{ <span class="hljs-number">123456</span>:<span class="hljs-number">10</span>_} <span class="hljs-comment"># ' 123_456'</span> |
| 515 | +{ <span class="hljs-number">123456</span>:+<span class="hljs-number">10</span>} <span class="hljs-comment"># ' +123456'</span> |
| 516 | +{<span class="hljs-number">-123456</span>:=<span class="hljs-number">10</span>} <span class="hljs-comment"># '- 123456'</span> |
| 517 | +{ <span class="hljs-number">123456</span>: } <span class="hljs-comment"># ' 123456'</span> |
| 518 | +{<span class="hljs-number">-123456</span>: } <span class="hljs-comment"># '-123456'</span> |
519 | 519 | </code></pre></div>
|
520 | 520 |
|
521 |
| -<div><h3 id="floats">Floats</h3><pre><code class="python language-python hljs">{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># ' 1.23'</span> |
522 |
| -{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>f} <span class="hljs-comment"># ' 1.235'</span> |
523 |
| -{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>e} <span class="hljs-comment"># ' 1.235e+00'</span> |
524 |
| -{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>%} <span class="hljs-comment"># ' 123.456%'</span> |
| 521 | +<div><h3 id="floats">Floats</h3><pre><code class="python language-python hljs">{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>} <span class="hljs-comment"># ' 1.23'</span> |
| 522 | +{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>f} <span class="hljs-comment"># ' 1.235'</span> |
| 523 | +{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>e} <span class="hljs-comment"># ' 1.235e+00'</span> |
| 524 | +{<span class="hljs-number">1.23456</span>:<span class="hljs-number">10.3</span>%} <span class="hljs-comment"># ' 123.456%'</span> |
525 | 525 | </code></pre></div>
|
526 | 526 |
|
527 | 527 | <div><h4 id="comparisonoffloatpresentationtypes">Comparison of float presentation types:</h4><pre><code class="text language-text">+----------------+----------------+---------------+----------------+-----------------+
|
|
551 | 551 | | 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
|
552 | 552 | +----------------+----------------+---------------+----------------+-----------------+
|
553 | 553 | </code></pre>
|
554 |
| -<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span> |
555 |
| -{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span> |
556 |
| -{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span> |
| 554 | +<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span> |
| 555 | +{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span> |
| 556 | +{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span> |
557 | 557 | </code></pre></div>
|
558 | 558 |
|
559 | 559 | <div><h2 id="numbers"><a href="#numbers" name="numbers">#</a>Numbers</h2><div><h3 id="types">Types</h3><pre><code class="python language-python hljs"><int> = int(<float/str/bool>) <span class="hljs-comment"># Or: math.floor(<float>)</span>
|
|
1337 | 1337 | <span class="hljs-keyword">pass</span>
|
1338 | 1338 | </code></pre></div>
|
1339 | 1339 |
|
1340 |
| -<div><h2 id="print"><a href="#print" name="print">#</a>Print</h2><pre><code class="python language-python hljs">print(<el_1>, ..., sep=<span class="hljs-string">' '</span>, end=<span class="hljs-string">'\n'</span>, file=sys.stdout, flush=<span class="hljs-keyword">False</span>) |
| 1340 | +<div class="pagebreak"></div><div><h2 id="print"><a href="#print" name="print">#</a>Print</h2><pre><code class="python language-python hljs">print(<el_1>, ..., sep=<span class="hljs-string">' '</span>, end=<span class="hljs-string">'\n'</span>, file=sys.stdout, flush=<span class="hljs-keyword">False</span>) |
1341 | 1341 | </code></pre></div>
|
1342 | 1342 |
|
1343 | 1343 | <ul>
|
|
1387 | 1387 |
|
1388 | 1388 | <ul>
|
1389 | 1389 | <li><strong><code class="python hljs"><span class="hljs-string">'encoding=None'</span></code> means default encoding is used, which is platform dependent. Best practice is to use <code class="python hljs"><span class="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li>
|
1390 |
| -<li><strong><code class="python hljs"><span class="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.</strong></li> |
| 1390 | +<li><strong><code class="python hljs"><span class="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.</strong></li> |
1391 | 1391 | <li><strong><code class="python hljs"><span class="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.</strong></li>
|
1392 | 1392 | </ul>
|
1393 | 1393 | <div><h3 id="modes">Modes</h3><ul>
|
|
1605 | 1605 | writer.writerows(rows)
|
1606 | 1606 | </code></pre></div>
|
1607 | 1607 |
|
1608 |
| -<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into separate file.</strong></p><div><h3 id="connect">Connect</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3 |
| 1608 | +<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into separate file.</strong></p><div><h3 id="connect">Connect</h3><p><strong>Opens a connection to the database file. Creates a new file if path doesn't exist.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3 |
1609 | 1609 | db = sqlite3.connect(<span class="hljs-string">'<path>'</span>) <span class="hljs-comment"># Also ':memory:'.</span>
|
1610 | 1610 | ...
|
1611 | 1611 | db.close()
|
1612 | 1612 | </code></pre></div></div>
|
1613 | 1613 |
|
1614 | 1614 |
|
1615 | 1615 |
|
1616 |
| -<ul> |
1617 |
| -<li><strong>New database will be created if path doesn't exist.</strong></li> |
1618 |
| -</ul> |
| 1616 | + |
1619 | 1617 | <div><h3 id="read-1">Read</h3><p><strong>Returned values can be of type str, int, float, bytes or None.</strong></p><pre><code class="python language-python hljs"><cursor> = db.execute(<span class="hljs-string">'<query>'</span>) <span class="hljs-comment"># Can raise sqlite3.OperationalError.</span>
|
1620 | 1618 | <tuple> = <cursor>.fetchone() <span class="hljs-comment"># Returns next row. Also next(<cursor>).</span>
|
1621 | 1619 | <list> = <cursor>.fetchall() <span class="hljs-comment"># Returns remaining rows.</span>
|
|
1702 | 1700 | (<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
|
1703 | 1701 | </code></pre></div>
|
1704 | 1702 |
|
1705 |
| -<div><h3 id="format-2">Format</h3><div><h4 id="forstandardsizesstartformatstringwith">For standard sizes start format string with:</h4><ul> |
| 1703 | +<div><h3 id="format-2">Format</h3></div><div><h4 id="forstandardsizesstartformatstringwith">For standard sizes start format string with:</h4><ul> |
1706 | 1704 | <li><strong><code class="python hljs"><span class="hljs-string">'='</span></code> - native byte order</strong></li>
|
1707 | 1705 | <li><strong><code class="python hljs"><span class="hljs-string">'<'</span></code> - little-endian</strong></li>
|
1708 | 1706 | <li><strong><code class="python hljs"><span class="hljs-string">'>'</span></code> - big-endian</strong></li>
|
1709 |
| -</ul><div><h4 id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4><ul> |
| 1707 | +</ul></div><div><h4 id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4><ul> |
1710 | 1708 | <li><strong><code class="python hljs"><span class="hljs-string">'x'</span></code> - pad byte</strong></li>
|
1711 | 1709 | <li><strong><code class="python hljs"><span class="hljs-string">'b'</span></code> - char (1)</strong></li>
|
1712 | 1710 | <li><strong><code class="python hljs"><span class="hljs-string">'h'</span></code> - short (2)</strong></li>
|
1713 | 1711 | <li><strong><code class="python hljs"><span class="hljs-string">'i'</span></code> - int (4)</strong></li>
|
1714 | 1712 | <li><strong><code class="python hljs"><span class="hljs-string">'l'</span></code> - long (4)</strong></li>
|
1715 | 1713 | <li><strong><code class="python hljs"><span class="hljs-string">'q'</span></code> - long long (8)</strong></li>
|
1716 |
| -</ul><div><h4 id="floatingpointtypes">Floating point types:</h4><ul> |
| 1714 | +</ul></div><div><h4 id="floatingpointtypes">Floating point types:</h4><ul> |
1717 | 1715 | <li><strong><code class="python hljs"><span class="hljs-string">'f'</span></code> - float (4)</strong></li>
|
1718 | 1716 | <li><strong><code class="python hljs"><span class="hljs-string">'d'</span></code> - double (8)</strong></li>
|
1719 |
| -</ul></div></div></div></div> |
| 1717 | +</ul></div> |
1720 | 1718 |
|
1721 | 1719 |
|
1722 | 1720 |
|
|
1737 | 1735 | </ul><pre><code class="python language-python hljs"><mview> = memoryview(<bytes/bytearray/array>)
|
1738 | 1736 | <num> = <mview>[<index>] <span class="hljs-comment"># Returns an int or a float.</span>
|
1739 | 1737 | <mview> = <mview>[<slice>] <span class="hljs-comment"># Mview with rearranged elements.</span>
|
1740 |
| -<mview> = <mview>.cast(<span class="hljs-string">'<typecode>'</span>) <span class="hljs-comment"># Casts a memoryview to a new format.</span> |
| 1738 | +<mview> = <mview>.cast(<span class="hljs-string">'<typecode>'</span>) <span class="hljs-comment"># Casts memoryview to the new format.</span> |
1741 | 1739 | <mview>.release() <span class="hljs-comment"># Releases the object's memory buffer.</span>
|
1742 | 1740 | </code></pre></div>
|
1743 | 1741 |
|
1744 | 1742 |
|
1745 |
| -<pre><code class="python language-python hljs"><bin_file>.write(<mview>) <span class="hljs-comment"># Writes mview to a binary file.</span> |
| 1743 | +<pre><code class="python language-python hljs"><bin_file>.write(<mview>) <span class="hljs-comment"># Appends mview to the binary file.</span> |
1746 | 1744 | <bytes> = bytes(<mview>) <span class="hljs-comment"># Creates a new bytes object.</span>
|
1747 | 1745 | <bytes> = <bytes>.join(<coll_of_mviews>) <span class="hljs-comment"># Joins mviews using bytes object as sep.</span>
|
1748 | 1746 | <list> = list(<mview>) <span class="hljs-comment"># Returns list of ints or floats.</span>
|
|
0 commit comments