|
1701 | 1701 |
|
1702 | 1702 | <div><h3 id="encode-1">Encode</h3><pre><code class="python language-python hljs"><bytes> = bytes(<coll_of_ints>) <span class="hljs-comment"># Ints must be in range from 0 to 255.</span> |
1703 | 1703 | <bytes> = bytes(<str>, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Or: <str>.encode('utf-8')</span> |
1704 | | -<bytes> = <int>.to_bytes(n_bytes) <span class="hljs-comment"># Also: `byteorder='big/little', signed=False`.</span> |
| 1704 | +<bytes> = <int>.to_bytes(n_bytes, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`</span> |
1705 | 1705 | <bytes> = bytes.fromhex(<span class="hljs-string">'<hex>'</span>) <span class="hljs-comment"># Hex numbers can be separated by spaces.</span> |
1706 | 1706 | </code></pre></div> |
1707 | 1707 |
|
1708 | 1708 | <div><h3 id="decode-1">Decode</h3><pre><code class="python language-python hljs"><list> = list(<bytes>) <span class="hljs-comment"># Returns ints in range from 0 to 255.</span> |
1709 | 1709 | <str> = str(<bytes>, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Or: <bytes>.decode('utf-8')</span> |
1710 | | -<int> = int.from_bytes(<bytes>) <span class="hljs-comment"># Also: `byteorder='big/little', signed=False`.</span> |
| 1710 | +<int> = int.from_bytes(<bytes>, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`</span> |
1711 | 1711 | <span class="hljs-string">'<hex>'</span> = <bytes>.hex() <span class="hljs-comment"># Returns a string of hexadecimal numbers.</span> |
1712 | 1712 | </code></pre></div> |
1713 | 1713 |
|
|
1786 | 1786 |
|
1787 | 1787 | <pre><code class="python language-python hljs"><list> = list(<mview>) <span class="hljs-comment"># Returns list of ints or floats.</span> |
1788 | 1788 | <str> = str(<mview>, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Treats mview as a bytes object.</span> |
1789 | | -<int> = int.from_bytes(<mview>, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`.</span> |
| 1789 | +<int> = int.from_bytes(<mview>, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`</span> |
1790 | 1790 | <span class="hljs-string">'<hex>'</span> = <mview>.hex() <span class="hljs-comment"># Treats mview as a bytes object.</span> |
1791 | 1791 | </code></pre> |
1792 | 1792 | <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 |
|
0 commit comments