Browse Source

Decorator, Struct

pull/135/head
Jure Šorn 2 years ago
parent
commit
02123b512f
2 changed files with 12 additions and 12 deletions
  1. 10
      README.md
  2. 14
      index.html

10
README.md

@ -894,7 +894,7 @@ def function_that_gets_passed_to_decorator():
```
### Debugger Example
**Decorator that prints function's name every time it gets called.**
**Decorator that prints function's name every time the function is called.**
```python
from functools import wraps
@ -1868,7 +1868,7 @@ def write_to_csv_file(filename, rows, dialect='excel'):
SQLite
------
**Server-less database engine that stores each database into a separate file.**
**A server-less database engine that stores each database into a separate file.**
### Connect
**Opens a connection to the database file. Creates a new file if path doesn't exist.**
@ -1981,8 +1981,8 @@ Struct
```python
from struct import pack, unpack
<bytes> = pack('<format>', <el> [, ...]) # Packages arguments into bytes object.
<tuple> = unpack('<format>', <bytes>) # Use iter_unpack() for iterator of tuples.
<bytes> = pack('<format>', <el_1> [, ...]) # Packages arguments into bytes object.
<tuple> = unpack('<format>', <bytes>) # Use iter_unpack() for iterator of tuples.
```
```python
@ -1999,7 +1999,7 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03'
* **`'>'` - Big-endian (also `'!'`).**
#### Besides numbers, pack() and unpack() also support bytes objects as part of the seqence:
* **`'c'` - A bytes object with single element. Use `'x'` for pad byte.**
* **`'c'` - A bytes object with a single element. Use `'x'` for pad byte.**
* **`'<n>s'` - A bytes object with n elements.**
#### Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:

14
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>June 15, 2022</aside>
<aside>June 16, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -757,7 +757,7 @@ creature = Creature(point, direction)
</code></pre></div>
<div><h3 id="debuggerexample">Debugger Example</h3><p><strong>Decorator that prints function's name every time it gets called.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> wraps
<div><h3 id="debuggerexample">Debugger Example</h3><p><strong>Decorator that prints function's name every time the function is called.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> wraps
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">debug</span><span class="hljs-params">(func)</span>:</span>
<span class="hljs-meta"> @wraps(func)</span>
@ -1559,7 +1559,7 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
writer.writerows(rows)
</code></pre></div>
<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into a separate file.</strong></p><div><h3 id="connect">Connect</h3><p><strong>Opens a connection to the database file. Creates a new file if path doesn't exist.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
<div><h2 id="sqlite"><a href="#sqlite" name="sqlite">#</a>SQLite</h2><p><strong>A server-less database engine that stores each database into a separate file.</strong></p><div><h3 id="connect">Connect</h3><p><strong>Opens a connection to the database file. Creates a new file if path doesn't exist.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sqlite3
&lt;conn&gt; = sqlite3.connect(&lt;path&gt;) <span class="hljs-comment"># Also ':memory:'.</span>
&lt;conn&gt;.close() <span class="hljs-comment"># Closes the connection.</span>
</code></pre></div></div>
@ -1643,8 +1643,8 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
<li><strong>Module that performs conversions between a sequence of numbers and a bytes object.</strong></li>
<li><strong>System’s type sizes, byte order, and alignment rules are used by default.</strong></li>
</ul><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> struct <span class="hljs-keyword">import</span> pack, unpack
&lt;bytes&gt; = pack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;el&gt; [, ...]) <span class="hljs-comment"># Packages arguments into bytes object.</span>
&lt;tuple&gt; = unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;) <span class="hljs-comment"># Use iter_unpack() for iterator of tuples.</span>
&lt;bytes&gt; = pack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;el_1&gt; [, ...]) <span class="hljs-comment"># Packages arguments into bytes object.</span>
&lt;tuple&gt; = unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;) <span class="hljs-comment"># Use iter_unpack() for iterator of tuples.</span>
</code></pre></div>
@ -1658,7 +1658,7 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
<li><strong><code class="python hljs"><span class="hljs-string">'&lt;'</span></code> - Little-endian.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'&gt;'</span></code> - Big-endian (also <code class="python hljs"><span class="hljs-string">'!'</span></code>).</strong></li>
</ul><div><h4 id="besidesnumberspackandunpackalsosupportbytesobjectsaspartoftheseqence">Besides numbers, pack() and unpack() also support bytes objects as part of the seqence:</h4><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'c'</span></code> - A bytes object with single element. Use <code class="python hljs"><span class="hljs-string">'x'</span></code> for pad byte.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'c'</span></code> - A bytes object with a single element. Use <code class="python hljs"><span class="hljs-string">'x'</span></code> for pad byte.</strong></li>
<li><strong><code class="apache hljs"><span class="hljs-section">'&lt;n&gt;s'</span><span class="hljs-attribute"></span></code> - A bytes object with n elements.</strong></li>
</ul></div></div><div><div><h4 id="integertypesuseacapitalletterforunsignedtypeminimumandstandardsizesareinbrackets">Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:</h4><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'b'</span></code> - char (1/1)</strong></li>
@ -2902,7 +2902,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>June 15, 2022</aside>
<aside>June 16, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

Loading…
Cancel
Save