|
1723 | 1723 |
|
1724 | 1724 |
|
1725 | 1725 | <div><h2 id="array"><a href="#array" name="array">#</a>Array</h2><p><strong>List that can only hold numbers of a predefined type. Available types and their sizes in bytes are listed above.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> array <span class="hljs-keyword">import</span> array
|
1726 |
| -<array> = array(<span class="hljs-string">'<typecode>'</span>, <collection>) <span class="hljs-comment"># Array from coll. of numbers.</span> |
1727 |
| -<array> = array(<span class="hljs-string">'<typecode>'</span>, <bytes>) <span class="hljs-comment"># Array from bytes object.</span> |
| 1726 | +<array> = array(<span class="hljs-string">'<typecode>'</span>, <collection>) <span class="hljs-comment"># Array from coll. of numbers.</span> |
| 1727 | +<array> = array(<span class="hljs-string">'<typecode>'</span>, <bytes>) <span class="hljs-comment"># Array from bytes object.</span> |
1728 | 1728 | <bytes> = <array>.tobytes()
|
1729 | 1729 | </code></pre></div>
|
1730 | 1730 |
|
1731 | 1731 |
|
1732 | 1732 | <div><h2 id="memoryview"><a href="#memoryview" name="memoryview">#</a>Memory View</h2><ul>
|
1733 |
| -<li><strong>A seqence object that points to the memory of another object.</strong></li> |
| 1733 | +<li><strong>A sequence object that points to the memory of another object.</strong></li> |
1734 | 1734 | <li><strong>Each element can reference a single or multiple consecutive bytes, depending on format.</strong></li>
|
1735 | 1735 | <li><strong>Order and number of elements can be changed with slicing.</strong></li>
|
1736 | 1736 | </ul><pre><code class="python language-python hljs"><mview> = memoryview(<bytes/bytearray/array>)
|
1737 | 1737 | <num> = <mview>[<index>] <span class="hljs-comment"># Can be int or float.</span>
|
1738 |
| -<mview> = <mview>[<slice>] <span class="hljs-comment"># Mview with rearanged elements.</span> |
| 1738 | +<mview> = <mview>[<slice>] <span class="hljs-comment"># Mview with rearranged elements.</span> |
1739 | 1739 | <mview> = <mview>.cast(<span class="hljs-string">'<typecode>'</span>) <span class="hljs-comment"># Casts a memoryview to a new format.</span>
|
1740 | 1740 | <mview>.release() <span class="hljs-comment"># Releases the object's memory buffer.</span>
|
1741 | 1741 | </code></pre></div>
|
|
1754 | 1754 | </code></pre></div>
|
1755 | 1755 |
|
1756 | 1756 |
|
1757 |
| -<pre><code class="python language-python hljs"><deque>.appendleft(<el>) <span class="hljs-comment"># Opposite element is dropped if full.</span> |
1758 |
| -<el> = <deque>.popleft() <span class="hljs-comment"># Raises IndexError if empty.</span> |
1759 |
| -<deque>.extendleft(<collection>) <span class="hljs-comment"># Collection gets reversed.</span> |
1760 |
| -<deque>.rotate(n=<span class="hljs-number">1</span>) <span class="hljs-comment"># Rotates elements to the right.</span> |
| 1757 | +<pre><code class="python language-python hljs"><deque>.appendleft(<el>) <span class="hljs-comment"># Opposite element is dropped if full.</span> |
| 1758 | +<el> = <deque>.popleft() <span class="hljs-comment"># Raises IndexError if empty.</span> |
| 1759 | +<deque>.extendleft(<collection>) <span class="hljs-comment"># Collection gets reversed.</span> |
| 1760 | +<deque>.rotate(n=<span class="hljs-number">1</span>) <span class="hljs-comment"># Rotates elements to the right.</span> |
1761 | 1761 | </code></pre>
|
1762 | 1762 | <div><h2 id="threading"><a href="#threading" name="threading">#</a>Threading</h2><ul>
|
1763 | 1763 | <li><strong>CPython interpreter can only run a single thread at a time.</strong></li>
|
|
1974 | 1974 | </code></pre></div></div>
|
1975 | 1975 |
|
1976 | 1976 |
|
1977 |
| -<div><h2 id="curses"><a href="#curses" name="curses">#</a>Curses</h2><div><h4 id="clearsterminalprintsmessageandwaitsforesckeypress">Clears terminal, prints message and waits for ESC key press:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> curses <span class="hljs-keyword">import</span> wrapper, curs_set, ascii |
| 1977 | +<div><h2 id="curses"><a href="#curses" name="curses">#</a>Curses</h2><div><h4 id="clearstheterminalprintsamessageandwaitsforanesckeypress">Clears the terminal, prints a message and waits for an ESC key press:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> curses <span class="hljs-keyword">import</span> wrapper, curs_set, ascii |
1978 | 1978 | <span class="hljs-keyword">from</span> curses <span class="hljs-keyword">import</span> KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_LEFT
|
1979 | 1979 |
|
1980 | 1980 | <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
|
|
0 commit comments