#### For standard type sizes and manual alignment (padding) start format string with:
* **`'='` - System's byte order (usually little-endian).**
* **`'<'` - Little-endian.**
* **`'<'` - Little-endian (i.e. least significant byte first).**
* **`'>'` - Big-endian (also `'!'`).**
#### Besides numbers, pack() and unpack() also support bytes objects as part of the sequence:
* **`'c'` - A bytes object with a single element. For pad byte use `'x'`.**
* **`'<n>s'` - A bytes object with n elements.**
* **`'<n>s'` - A bytes object with n elements (not effected by byte order).**
#### Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:
* **`'b'` - char (1/1)**
@ -2414,7 +2414,7 @@ plt.clf() # Clears the figure.
Table
-----
#### Prints a CSV file as an ASCII table:
#### Prints a CSV spreadsheet to the console:
```python
# $ pip3 install tabulate
import csv, tabulate
@ -2676,7 +2676,7 @@ import numpy as np
<array> = np.tile/repeat(<array>, <int/list> [, axis]) # Tiles array or repeats its elements.
```
* **Shape is a tuple of dimension sizes. A 100x50 RGB image has shape (50, 100, 3).**
* **Axis is an index of the dimension that gets aggregated. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).**
* **Axis is an index of a dimension. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).**
### Indexing
```perl
@ -2858,21 +2858,21 @@ import wave
```
```python
<Wave>= wave.open('<path>', 'rb') # Opens the WAV file.
<int>= <Wave>.getframerate() # Returns number of frames per second.
<int>= <Wave>.getnchannels() # Returns number of samples per frame.
<int>= <Wave>.getsampwidth() # Returns number of bytes per sample.
<params> = <Wave>.getparams() # Returns collection of listed params.
<bytes>= <Wave>.readframes(nframes) # Returns next n frames. All if -1.
<Wave> = wave.open('<path>', 'rb') # Opens the WAV file.
<int> = <Wave>.getframerate() # Returns number of frames per second.
<int> = <Wave>.getnchannels() # Returns number of samples per frame.
<int> = <Wave>.getsampwidth() # Returns number of bytes per sample.
<tuple> = <Wave>.getparams() # Returns namedtuple of all parameters.
<bytes> = <Wave>.readframes(nframes) # Returns next n frames. All if -1.
```
```python
<Wave> = wave.open('<path>', 'wb') # Opens WAV file for writing.
<Wave>.setframerate(<int>) # Pass 44100 for CD, 48000 for video.
<Wave>.setnchannels(<int>) # Pass 1 for mono, 2 for stereo.
<Wave>.setsampwidth(<int>) # Pass 2 for CD, 3 for hi-res sound.
<Wave>.setparams(<params>) # Sets all parameters.
<Wave>.writeframes(<bytes>) # Appends frames to the file.
<Wave> = wave.open('<path>', 'wb') # Creates/truncates a file for writing.
<Wave>.setframerate(<int>) # Pass 44100 for CD, 48000 for video.
<Wave>.setnchannels(<int>) # Pass 1 for mono, 2 for stereo.
<Wave>.setsampwidth(<int>) # Pass 2 for CD, 3 for hi-res sound.
<Wave>.setparams(<tuple>) # Sets all parameters.
<Wave>.writeframes(<bytes>) # Appends frames to the file.
```
* **Bytes object contains a sequence of frames, each consisting of one or more samples.**
* **In a stereo signal, the first sample of a frame belongs to the left channel.**
@ -3007,7 +3007,7 @@ while not pg.event.get(pg.QUIT):
```python
<bool> = <Rect>.collidepoint((x, y)) # Checks if rectangle contains the point.
<bool> = <Rect>.colliderect(<Rect>) # Checks if two rectangles overlap.
<bool> = <Rect>.colliderect(<Rect>) # Checks if the two rectangles overlap.
<int> = <Rect>.collidelist(<list_of_Rect>) # Returns index of first colliding Rect or -1.
<list> = <Rect>.collidelistall(<list_of_Rect>) # Returns indexes of all colliding rectangles.
```
@ -3025,7 +3025,7 @@ while not pg.event.get(pg.QUIT):
```python
<Surf>.fill(color) # Tuple, Color('#rrggbb[aa]') or Color(<name>).
<Surf>.set_at((x, y), color) # Updates pixel. Also <Surf>.get_at((x, y)).
<Surf>.blit(<Surf>, (x, y)) # Draws passed surface to the surface.
<Surf>.blit(<Surf>, (x, y)) # Draws passed surface at specified location.
```
```python
@ -3051,7 +3051,7 @@ rect(<Surf>, color, <Rect>, width=0) # Also polygon(<Surf>, color, po
### Sound
```python
<Sound> = pg.mixer.Sound(<path/file/bytes>) # WAV file or bytes/array of signed shorts.
<Sound>.play/stop() # Also <Sound>.set_volume(<float>).
<Sound>.play/stop() # Also set_volume(<float>), fadeout(msec).
```
### Basic Mario Brothers Example
@ -3373,7 +3373,7 @@ c 7 8 6
<GB> = <DF>.groupby(column_key/s) # Splits DF into groups based on passed column.
<DF> = <GB>.apply(<func>) # Maps each group. Func can return DF, Sr or el.
<GB> = <GB>[column_key] # Single column GB. All operations return a Sr.
<Sr> = <GB>.size() # A Sr of group sizes. Keys are group "names".
<Sr> = <GB>.size() # A Sr of group sizes. Same keys as get_group().
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'%Z'</span></code> accepts <codeclass="python hljs"><spanclass="hljs-string">'UTC/GMT'</span></code> and local timezone's code and returns timezone's name, <codeclass="python hljs"><spanclass="hljs-string">'UTC[±HH:MM]'</span></code> if timezone is nameless, or an empty string if datetime is naive.</strong></li>
</ul>
<div><h3id="arithmetics">Arithmetics</h3><pre><codeclass="python language-python apache hljs"><bool> = <D/T/DTn>><D/T/DTn><spanclass="hljs-comment"># Ignores time jumps (fold attribute). Also ==.</span>
<bool> = <DTa>><DTa><spanclass="hljs-comment"># Ignores time jumps if they share tzinfo object.</span>
<bool> = <DTa>><DTa><spanclass="hljs-comment"># Ignores jumps if they share tz object. Broken ==.</span>
<TD> = <D/DTn> - <D/DTn><spanclass="hljs-comment"># Ignores jumps. Convert to UTC for actual delta.</span>
<TD> = <DTa> - <DTa><spanclass="hljs-comment"># Ignores time jumps if they share tzinfo object.</span>
<TD> = <DTa> - <DTa><spanclass="hljs-comment"># Ignores jumps if they share tzinfo object.</span>
<D/DT> = <D/DT> ± <TD><spanclass="hljs-comment"># Returned datetime can fall into missing hour.</span>
<div><h2id="bytes"><ahref="#bytes"name="bytes">#</a>Bytes</h2><p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.</strong></p><pre><codeclass="python language-python hljs"><bytes> = <spanclass="hljs-string">b'<str>'</span><spanclass="hljs-comment"># Only accepts ASCII characters and \x00-\xff.</span>
<int> = <bytes>[<index>] <spanclass="hljs-comment"># Returns an int in range from 0 to 255.</span>
<bytes> = <bytes>[<slice>] <spanclass="hljs-comment"># Returns bytes even if it has only one element.</span>
<bytes> = <bytes>.join(<coll_of_bytes>) <spanclass="hljs-comment"># Joins elements using bytes as a separator.</span>
<div><h2id="bytes"><ahref="#bytes"name="bytes">#</a>Bytes</h2><p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.</strong></p><pre><codeclass="python language-python hljs"><bytes> = <spanclass="hljs-string">b'<str>'</span><spanclass="hljs-comment"># Only accepts ASCII characters and \x00-\xff.</span>
<int> = <bytes>[<index>] <spanclass="hljs-comment"># Returns an int in range from 0 to 255.</span>
<bytes> = <bytes>[<slice>] <spanclass="hljs-comment"># Returns bytes even if it has only one element.</span>
<bytes> = <bytes>.join(<coll_of_bytes>) <spanclass="hljs-comment"># Joins elements using bytes as a separator.</span>
</code></pre></div>
<div><h3id="encode-1">Encode</h3><pre><codeclass="python language-python hljs"><bytes> = bytes(<coll_of_ints>) <spanclass="hljs-comment"># Ints must be in range from 0 to 255.</span>
<bytes> = bytes.fromhex(<spanclass="hljs-string">'<hex>'</span>) <spanclass="hljs-comment"># Hex pairs can be separated by whitespaces.</span>
<div><h3id="encode-1">Encode</h3><pre><codeclass="python language-python hljs"><bytes> = bytes(<coll_of_ints>) <spanclass="hljs-comment"># Ints must be in range from 0 to 255.</span>
<bytes> = bytes.fromhex(<spanclass="hljs-string">'<hex>'</span>) <spanclass="hljs-comment"># Hex pairs can be separated by whitespaces.</span>
</code></pre></div>
<div><h3id="decode-1">Decode</h3><pre><codeclass="python language-python hljs"><list> = list(<bytes>) <spanclass="hljs-comment"># Returns ints in range from 0 to 255.</span>
<div><h3id="decode-1">Decode</h3><pre><codeclass="python language-python hljs"><list> = list(<bytes>) <spanclass="hljs-comment"># Returns ints in range from 0 to 255.</span>
<h3id="format-2">Format</h3><div><h4id="forstandardtypesizesandmanualalignmentpaddingstartformatstringwith">For standard type sizes and manual alignment (padding) start format string with:</h4><ul>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'='</span></code> - System's byte order (usually little-endian).</strong></li>
</ul><div><h4id="besidesnumberspackandunpackalsosupportbytesobjectsaspartofthesequence">Besides numbers, pack() and unpack() also support bytes objects as part of the sequence:</h4><ul>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'c'</span></code> - A bytes object with a single element. For pad byte use <codeclass="python hljs"><spanclass="hljs-string">'x'</span></code>.</strong></li>
<li><strong><codeclass="apache hljs"><spanclass="hljs-section">'<n>s'</span><spanclass="hljs-attribute"></span></code> - A bytes object with n elements.</strong></li>
<li><strong><codeclass="apache hljs"><spanclass="hljs-section">'<n>s'</span><spanclass="hljs-attribute"></span></code> - A bytes object with n elements (not effected by byte order).</strong></li>
</ul></div></div><div><div><h4id="integertypesuseacapitalletterforunsignedtypeminimumandstandardsizesareinbrackets">Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:</h4><ul>
plt.clf() <spanclass="hljs-comment"># Clears the figure.</span>
</code></pre></div>
<div><h2id="table"><ahref="#table"name="table">#</a>Table</h2><div><h4id="printsacsvfileasanasciitable">Prints a CSV file as an ASCII table:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install tabulate</span>
<div><h2id="table"><ahref="#table"name="table">#</a>Table</h2><div><h4id="printsacsvspreadsheettotheconsole">Prints a CSV spreadsheet to the console:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install tabulate</span>
<li><strong>Shape is a tuple of dimension sizes. A 100x50 RGB image has shape (50, 100, 3).</strong></li>
<li><strong>Axis is an index of the dimension that gets aggregated. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).</strong></li>
<li><strong>Axis is an index of a dimension. Leftmost dimension has index 0. Summing the RGB image along axis 2 will return a greyscale image with shape (50, 100).</strong></li>
<div><h3id="sound">Sound</h3><pre><codeclass="python language-python hljs"><Sound> = pg.mixer.Sound(<path/file/bytes>) <spanclass="hljs-comment"># WAV file or bytes/array of signed shorts.</span>
<Sound>.play/stop() <spanclass="hljs-comment"># Also <Sound>.set_volume(<float>).</span>
<Sound>.play/stop() <spanclass="hljs-comment"># Also set_volume(<float>), fadeout(msec).</span>
@ -2761,7 +2761,7 @@ c <span class="hljs-number">7</span> <span class="hljs-number">8</span> <span
<pre><codeclass="python language-python hljs"><GB> = <DF>.groupby(column_key/s) <spanclass="hljs-comment"># Splits DF into groups based on passed column.</span>
<DF> = <GB>.apply(<func>) <spanclass="hljs-comment"># Maps each group. Func can return DF, Sr or el.</span>
<GB> = <GB>[column_key] <spanclass="hljs-comment"># Single column GB. All operations return a Sr.</span>
<Sr> = <GB>.size() <spanclass="hljs-comment"># A Sr of group sizes. Keys are group "names".</span>
<Sr> = <GB>.size() <spanclass="hljs-comment"># A Sr of group sizes. Same keys as get_group().</span>