|
54 | 54 |
|
55 | 55 | <body>
|
56 | 56 | <header>
|
57 |
| - <aside>September 24, 2024</aside> |
| 57 | + <aside>September 27, 2024</aside> |
58 | 58 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
59 | 59 | </header>
|
60 | 60 |
|
@@ -1692,26 +1692,26 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
|
1692 | 1692 | <pre><code class="python language-python hljs"><array> = array(<span class="hljs-string">'<typecode>'</span>, <coll_of_nums>) <span class="hljs-comment"># Array from collection of numbers.</span>
|
1693 | 1693 | <array> = array(<span class="hljs-string">'<typecode>'</span>, <bytes>) <span class="hljs-comment"># Copies bytes to array's memory.</span>
|
1694 | 1694 | <array> = array(<span class="hljs-string">'<typecode>'</span>, <array>) <span class="hljs-comment"># Treats array as a sequence of numbers.</span>
|
1695 |
| -<array>.fromfile(<file>, n_items) <span class="hljs-comment"># Appends items from binary file.</span> |
| 1695 | +<array>.fromfile(<file>, n_items) <span class="hljs-comment"># Appends items from the binary file.</span> |
1696 | 1696 | </code></pre>
|
1697 | 1697 | <pre><code class="python language-python hljs"><bytes> = bytes(<array>) <span class="hljs-comment"># Returns a copy of array's memory.</span>
|
1698 | 1698 | <file>.write(<array>) <span class="hljs-comment"># Writes array's memory to binary file.</span>
|
1699 | 1699 | </code></pre>
|
1700 |
| -<div><h2 id="memoryview"><a href="#memoryview" name="memoryview">#</a>Memory View</h2><p><strong>A sequence object that points to the memory of another bytes-like object. Each element can reference a single or multiple consecutive bytes, depending on format. Order and number of elements can be changed with slicing.</strong></p><pre><code class="python language-python hljs"><mview> = memoryview(<bytes/bytearray/array>) <span class="hljs-comment"># Immutable if bytes, else mutable.</span> |
1701 |
| -<obj> = <mview>[index] <span class="hljs-comment"># Returns int/float (bytes if format is 'c').</span> |
1702 |
| -<mview> = <mview>[<slice>] <span class="hljs-comment"># Returns mview with rearranged elements.</span> |
| 1700 | +<div><h2 id="memoryview"><a href="#memoryview" name="memoryview">#</a>Memory View</h2><p><strong>A sequence object that points to the memory of another bytes-like object. Each element can reference a single or multiple consecutive bytes, depending on format. Order and number of elements can be changed with slicing.</strong></p><pre><code class="python language-python hljs"><mview> = memoryview(<bytes/bytearray/array>) <span class="hljs-comment"># Immutable if bytes is passed, else mutable.</span> |
| 1701 | +<obj> = <mview>[index] <span class="hljs-comment"># Returns int/float. Bytes if format is 'c'.</span> |
| 1702 | +<mview> = <mview>[<slice>] <span class="hljs-comment"># Returns memoryview with rearranged elements.</span> |
1703 | 1703 | <mview> = <mview>.cast(<span class="hljs-string">'<typecode>'</span>) <span class="hljs-comment"># Only works between B/b/c and other types.</span>
|
1704 | 1704 | <mview>.release() <span class="hljs-comment"># Releases memory buffer of the base object.</span>
|
1705 | 1705 | </code></pre></div>
|
1706 | 1706 |
|
1707 | 1707 |
|
1708 | 1708 | <pre><code class="python language-python hljs"><bytes> = bytes(<mview>) <span class="hljs-comment"># Returns a new bytes object.</span>
|
1709 |
| -<bytes> = <bytes>.join(<coll_of_mviews>) <span class="hljs-comment"># Joins mviews using bytes as a separator.</span> |
1710 |
| -<array> = array(<span class="hljs-string">'<typecode>'</span>, <mview>) <span class="hljs-comment"># Treats mview as a sequence of numbers.</span> |
1711 |
| -<file>.write(<mview>) <span class="hljs-comment"># Writes `bytes(<mview>)` to binary file.</span> |
| 1709 | +<bytes> = <bytes>.join(<coll_of_mviews>) <span class="hljs-comment"># Joins memoryviews using bytes as a separator.</span> |
| 1710 | +<array> = array(<span class="hljs-string">'<typecode>'</span>, <mview>) <span class="hljs-comment"># Treats memoryview as a sequence of numbers.</span> |
| 1711 | +<file>.write(<mview>) <span class="hljs-comment"># Writes `bytes(<mview>)` to the binary file.</span> |
1712 | 1712 | </code></pre>
|
1713 | 1713 | <pre><code class="python language-python hljs"><list> = list(<mview>) <span class="hljs-comment"># Returns a list of ints, floats or bytes.</span>
|
1714 |
| -<str> = str(<mview>, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Treats mview as a bytes object.</span> |
| 1714 | +<str> = str(<mview>, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Treats memoryview as a bytes object.</span> |
1715 | 1715 | <str> = <mview>.hex() <span class="hljs-comment"># Returns hex pairs. Accepts `sep=<str>`.</span>
|
1716 | 1716 | </code></pre>
|
1717 | 1717 | <div><h2 id="deque"><a href="#deque" name="deque">#</a>Deque</h2><p><strong>A thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> deque
|
@@ -2931,7 +2931,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
|
2931 | 2931 |
|
2932 | 2932 |
|
2933 | 2933 | <footer>
|
2934 |
| - <aside>September 24, 2024</aside> |
| 2934 | + <aside>September 27, 2024</aside> |
2935 | 2935 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
2936 | 2936 | </footer>
|
2937 | 2937 |
|
|
0 commit comments