Skip to content

Commit 1d75ae3

Browse files
committed
Struct
1 parent 4e83b16 commit 1d75ae3

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ print(<el_1>, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
12461246
```
12471247

12481248
* **Use `'file=sys.stderr'` for errors.**
1249+
* **Use `'flush=True'` to forcibly flush the stream.**
12491250

12501251
### Pretty Print
12511252
```python
@@ -1592,12 +1593,12 @@ def write_bytes(filename, bytes_obj):
15921593

15931594
Struct
15941595
------
1595-
* **Module that performs conversions between Python values and a C struct, represented as a Python bytes object.**
1596+
* **Module that performs conversions between a sequence of numbers and a C struct, represented as a Python bytes object.**
15961597
* **Machine’s native type sizes and byte order are used by default.**
15971598

15981599
```python
15991600
from struct import pack, unpack, iter_unpack, calcsize
1600-
<bytes> = pack('<format>', <value_1> [, <value_2>, ...])
1601+
<bytes> = pack('<format>', <num_1> [, <num_2>, ...])
16011602
<tuple> = unpack('<format>', <bytes>)
16021603
<tuples> = iter_unpack('<format>', <bytes>)
16031604
```
@@ -1618,20 +1619,22 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03'
16181619
* **`'<'` - little-endian**
16191620
* **`'>'` - big-endian**
16201621

1621-
#### Use capital letter for unsigned type. Standard sizes are in brackets:
1622+
#### Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:
16221623
* **`'x'` - pad byte**
16231624
* **`'b'` - char (1)**
16241625
* **`'h'` - short (2)**
16251626
* **`'i'` - int (4)**
16261627
* **`'l'` - long (4)**
16271628
* **`'q'` - long long (8)**
1629+
1630+
#### Floating point types:
16281631
* **`'f'` - float (4)**
16291632
* **`'d'` - double (8)**
16301633

16311634

16321635
Array
16331636
-----
1634-
**List that can hold only elements of predefined type. Available types and their sizes are listed above.**
1637+
**List that can only hold numbers of predefined type. Available types and their sizes in bytes are listed above.**
16351638

16361639
```python
16371640
from array import array
@@ -1671,7 +1674,7 @@ from collections import deque
16711674
[2, 3, 4]
16721675
>>> a.appendleft(5)
16731676
[5, 2, 3]
1674-
>>> a.insert(6, 1)
1677+
>>> a.insert(1, 6)
16751678
IndexError: deque already at its maximum size
16761679
```
16771680

index.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ <h2 id="print"><a href="#print" name="print">#</a>Print</h2>
11391139
</code></pre>
11401140
<ul>
11411141
<li><strong>Use <code class="python hljs"><span class="hljs-string">'file=sys.stderr'</span></code> for errors.</strong></li>
1142+
<li><strong>Use <code class="python hljs"><span class="hljs-string">'flush=True'</span></code> to forcibly flush the stream.</strong></li>
11421143
</ul>
11431144
<h3 id="prettyprint">Pretty Print</h3>
11441145
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> pprint <span class="hljs-keyword">import</span> pprint
@@ -1395,11 +1396,11 @@ <h3 id="writebytestofile">Write Bytes to File</h3>
13951396
</code></pre>
13961397
<h2 id="struct"><a href="#struct" name="struct">#</a>Struct</h2>
13971398
<ul>
1398-
<li><strong>Module that performs conversions between Python values and a C struct, represented as a Python bytes object.</strong></li>
1399+
<li><strong>Module that performs conversions between a sequence of numbers and a C struct, represented as a Python bytes object.</strong></li>
13991400
<li><strong>Machine’s native type sizes and byte order are used by default.</strong></li>
14001401
</ul>
14011402
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> struct <span class="hljs-keyword">import</span> pack, unpack, iter_unpack, calcsize
1402-
&lt;bytes&gt; = pack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;value_1&gt; [, &lt;value_2&gt;, ...])
1403+
&lt;bytes&gt; = pack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;num_1&gt; [, &lt;num_2&gt;, ...])
14031404
&lt;tuple&gt; = unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)
14041405
&lt;tuples&gt; = iter_unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)
14051406
</code></pre>
@@ -1418,19 +1419,22 @@ <h4 id="forstandardsizesstartformatstringwith">For standard sizes start format s
14181419
<li><strong><code class="python hljs"><span class="hljs-string">'&lt;'</span></code> - little-endian</strong></li>
14191420
<li><strong><code class="python hljs"><span class="hljs-string">'&gt;'</span></code> - big-endian</strong></li>
14201421
</ul>
1421-
<h4 id="usecapitalletterforunsignedtypestandardsizesareinbrackets">Use capital letter for unsigned type. Standard sizes are in brackets:</h4>
1422+
<h4 id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4>
14221423
<ul>
14231424
<li><strong><code class="python hljs"><span class="hljs-string">'x'</span></code> - pad byte</strong></li>
14241425
<li><strong><code class="python hljs"><span class="hljs-string">'b'</span></code> - char (1)</strong></li>
14251426
<li><strong><code class="python hljs"><span class="hljs-string">'h'</span></code> - short (2)</strong></li>
14261427
<li><strong><code class="python hljs"><span class="hljs-string">'i'</span></code> - int (4)</strong></li>
14271428
<li><strong><code class="python hljs"><span class="hljs-string">'l'</span></code> - long (4)</strong></li>
14281429
<li><strong><code class="python hljs"><span class="hljs-string">'q'</span></code> - long long (8)</strong></li>
1430+
</ul>
1431+
<h4 id="floatingpointtypes">Floating point types:</h4>
1432+
<ul>
14291433
<li><strong><code class="python hljs"><span class="hljs-string">'f'</span></code> - float (4)</strong></li>
14301434
<li><strong><code class="python hljs"><span class="hljs-string">'d'</span></code> - double (8)</strong></li>
14311435
</ul>
14321436
<h2 id="array"><a href="#array" name="array">#</a>Array</h2>
1433-
<p><strong>List that can hold only elements of predefined type. Available types and their sizes are listed above.</strong></p>
1437+
<p><strong>List that can only hold numbers of predefined type. Available types and their sizes in bytes are listed above.</strong></p>
14341438
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> array <span class="hljs-keyword">import</span> array
14351439
&lt;array&gt; = array(<span class="hljs-string">'&lt;typecode&gt;'</span> [, &lt;collection&gt;])
14361440
</code></pre>
@@ -1454,7 +1458,7 @@ <h2 id="deque"><a href="#deque" name="deque">#</a>Deque</h2>
14541458
[<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
14551459
<span class="hljs-meta">&gt;&gt;&gt; </span>a.appendleft(<span class="hljs-number">5</span>)
14561460
[<span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
1457-
<span class="hljs-meta">&gt;&gt;&gt; </span>a.insert(<span class="hljs-number">6</span>, <span class="hljs-number">1</span>)
1461+
<span class="hljs-meta">&gt;&gt;&gt; </span>a.insert(<span class="hljs-number">1</span>, <span class="hljs-number">6</span>)
14581462
IndexError: deque already at its maximum size
14591463
</code></pre>
14601464
<h2 id="threading"><a href="#threading" name="threading">#</a>Threading</h2>

0 commit comments

Comments
 (0)