Skip to content

Commit 9639250

Browse files
committed
Memoryview
1 parent 7b0a9b7 commit 9639250

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ from array import array
20442044
<array> = array('<typecode>', <coll_of_nums>) # Array from collection of numbers.
20452045
<array> = array('<typecode>', <bytes>) # Copies bytes to array's memory.
20462046
<array> = array('<typecode>', <array>) # Treats array as a sequence of numbers.
2047-
<array>.fromfile(<file>, n_items) # Appends items from binary file.
2047+
<array>.fromfile(<file>, n_items) # Appends items from the binary file.
20482048
```
20492049

20502050
```python
@@ -2058,23 +2058,23 @@ Memory View
20582058
**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.**
20592059

20602060
```python
2061-
<mview> = memoryview(<bytes/bytearray/array>) # Immutable if bytes, else mutable.
2062-
<obj> = <mview>[index] # Returns int/float (bytes if format is 'c').
2063-
<mview> = <mview>[<slice>] # Returns mview with rearranged elements.
2061+
<mview> = memoryview(<bytes/bytearray/array>) # Immutable if bytes is passed, else mutable.
2062+
<obj> = <mview>[index] # Returns int/float. Bytes if format is 'c'.
2063+
<mview> = <mview>[<slice>] # Returns memoryview with rearranged elements.
20642064
<mview> = <mview>.cast('<typecode>') # Only works between B/b/c and other types.
20652065
<mview>.release() # Releases memory buffer of the base object.
20662066
```
20672067

20682068
```python
20692069
<bytes> = bytes(<mview>) # Returns a new bytes object.
2070-
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes as a separator.
2071-
<array> = array('<typecode>', <mview>) # Treats mview as a sequence of numbers.
2072-
<file>.write(<mview>) # Writes `bytes(<mview>)` to binary file.
2070+
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins memoryviews using bytes as a separator.
2071+
<array> = array('<typecode>', <mview>) # Treats memoryview as a sequence of numbers.
2072+
<file>.write(<mview>) # Writes `bytes(<mview>)` to the binary file.
20732073
```
20742074

20752075
```python
20762076
<list> = list(<mview>) # Returns a list of ints, floats or bytes.
2077-
<str> = str(<mview>, 'utf-8') # Treats mview as a bytes object.
2077+
<str> = str(<mview>, 'utf-8') # Treats memoryview as a bytes object.
20782078
<str> = <mview>.hex() # Returns hex pairs. Accepts `sep=<str>`.
20792079
```
20802080

index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<body>
5656
<header>
57-
<aside>September 24, 2024</aside>
57+
<aside>September 27, 2024</aside>
5858
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
5959
</header>
6060

@@ -1692,26 +1692,26 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
16921692
<pre><code class="python language-python hljs">&lt;array&gt; = array(<span class="hljs-string">'&lt;typecode&gt;'</span>, &lt;coll_of_nums&gt;) <span class="hljs-comment"># Array from collection of numbers.</span>
16931693
&lt;array&gt; = array(<span class="hljs-string">'&lt;typecode&gt;'</span>, &lt;bytes&gt;) <span class="hljs-comment"># Copies bytes to array's memory.</span>
16941694
&lt;array&gt; = array(<span class="hljs-string">'&lt;typecode&gt;'</span>, &lt;array&gt;) <span class="hljs-comment"># Treats array as a sequence of numbers.</span>
1695-
&lt;array&gt;.fromfile(&lt;file&gt;, n_items) <span class="hljs-comment"># Appends items from binary file.</span>
1695+
&lt;array&gt;.fromfile(&lt;file&gt;, n_items) <span class="hljs-comment"># Appends items from the binary file.</span>
16961696
</code></pre>
16971697
<pre><code class="python language-python hljs">&lt;bytes&gt; = bytes(&lt;array&gt;) <span class="hljs-comment"># Returns a copy of array's memory.</span>
16981698
&lt;file&gt;.write(&lt;array&gt;) <span class="hljs-comment"># Writes array's memory to binary file.</span>
16991699
</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">&lt;mview&gt; = memoryview(&lt;bytes/bytearray/array&gt;) <span class="hljs-comment"># Immutable if bytes, else mutable.</span>
1701-
&lt;obj&gt; = &lt;mview&gt;[index] <span class="hljs-comment"># Returns int/float (bytes if format is 'c').</span>
1702-
&lt;mview&gt; = &lt;mview&gt;[&lt;slice&gt;] <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">&lt;mview&gt; = memoryview(&lt;bytes/bytearray/array&gt;) <span class="hljs-comment"># Immutable if bytes is passed, else mutable.</span>
1701+
&lt;obj&gt; = &lt;mview&gt;[index] <span class="hljs-comment"># Returns int/float. Bytes if format is 'c'.</span>
1702+
&lt;mview&gt; = &lt;mview&gt;[&lt;slice&gt;] <span class="hljs-comment"># Returns memoryview with rearranged elements.</span>
17031703
&lt;mview&gt; = &lt;mview&gt;.cast(<span class="hljs-string">'&lt;typecode&gt;'</span>) <span class="hljs-comment"># Only works between B/b/c and other types.</span>
17041704
&lt;mview&gt;.release() <span class="hljs-comment"># Releases memory buffer of the base object.</span>
17051705
</code></pre></div>
17061706

17071707

17081708
<pre><code class="python language-python hljs">&lt;bytes&gt; = bytes(&lt;mview&gt;) <span class="hljs-comment"># Returns a new bytes object.</span>
1709-
&lt;bytes&gt; = &lt;bytes&gt;.join(&lt;coll_of_mviews&gt;) <span class="hljs-comment"># Joins mviews using bytes as a separator.</span>
1710-
&lt;array&gt; = array(<span class="hljs-string">'&lt;typecode&gt;'</span>, &lt;mview&gt;) <span class="hljs-comment"># Treats mview as a sequence of numbers.</span>
1711-
&lt;file&gt;.write(&lt;mview&gt;) <span class="hljs-comment"># Writes `bytes(&lt;mview&gt;)` to binary file.</span>
1709+
&lt;bytes&gt; = &lt;bytes&gt;.join(&lt;coll_of_mviews&gt;) <span class="hljs-comment"># Joins memoryviews using bytes as a separator.</span>
1710+
&lt;array&gt; = array(<span class="hljs-string">'&lt;typecode&gt;'</span>, &lt;mview&gt;) <span class="hljs-comment"># Treats memoryview as a sequence of numbers.</span>
1711+
&lt;file&gt;.write(&lt;mview&gt;) <span class="hljs-comment"># Writes `bytes(&lt;mview&gt;)` to the binary file.</span>
17121712
</code></pre>
17131713
<pre><code class="python language-python hljs">&lt;list&gt; = list(&lt;mview&gt;) <span class="hljs-comment"># Returns a list of ints, floats or bytes.</span>
1714-
&lt;str&gt; = str(&lt;mview&gt;, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Treats mview as a bytes object.</span>
1714+
&lt;str&gt; = str(&lt;mview&gt;, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Treats memoryview as a bytes object.</span>
17151715
&lt;str&gt; = &lt;mview&gt;.hex() <span class="hljs-comment"># Returns hex pairs. Accepts `sep=&lt;str&gt;`.</span>
17161716
</code></pre>
17171717
<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
29312931

29322932

29332933
<footer>
2934-
<aside>September 24, 2024</aside>
2934+
<aside>September 27, 2024</aside>
29352935
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29362936
</footer>
29372937

0 commit comments

Comments
 (0)