Browse Source

Decorator, SQLite

pull/144/merge
Jure Šorn 6 months ago
parent
commit
03426b838f
3 changed files with 36 additions and 36 deletions
  1. 22
      README.md
  2. 26
      index.html
  3. 24
      parse.js

22
README.md

@ -925,7 +925,7 @@ from functools import cache
def fib(n):
return n if n < 2 else fib(n-2) + fib(n-1)
```
* **Potential problem with cache is that it can grow indefinitely. To clear the cache run `'fib.cache_clear()'` or use `'@functools.lru_cache(maxsize=<int>)'` instead.**
* **Potential problem with cache is that it can grow indefinitely. To clear its stored values run `'fib.cache_clear()'`, or use `'@lru_cache(maxsize=<int>)'` decorator instead.**
* **CPython interpreter limits recursion depth to 3000 by default. To increase it run `'sys.setrecursionlimit(<int>)'`.**
### Parametrized Decorator
@ -1937,14 +1937,14 @@ with <conn>.begin(): ... # Exits the block with commit or
```
```text
+------------+--------------+----------+----------------------------------+
| Dialect | pip3 install | import | Dependencies |
+------------+--------------+----------+----------------------------------+
| mysql | mysqlclient | MySQLdb | www.pypi.org/project/mysqlclient |
| postgresql | psycopg2 | psycopg2 | www.pypi.org/project/psycopg2 |
| mssql | pyodbc | pyodbc | www.pypi.org/project/pyodbc |
| oracle | oracledb | oracledb | www.pypi.org/project/oracledb |
+------------+--------------+----------+----------------------------------+
+-----------------+--------------+----------------------------------+
| Dialect | pip3 install | Dependencies |
+-----------------+--------------+----------------------------------+
| mysql | mysqlclient | www.pypi.org/project/mysqlclient |
| postgresql | psycopg2 | www.pypi.org/project/psycopg2 |
| mssql | pyodbc | www.pypi.org/project/pyodbc |
| oracle+oracledb | oracledb | www.pypi.org/project/oracledb |
+-----------------+--------------+----------------------------------+
```
@ -2525,7 +2525,7 @@ from selenium import webdriver
<El>.click/clear() # Also <El>.send_keys(<str>).
```
#### XPath — also available in lxml, Scrapy, and browser's console via `'$x(<xpath>)'`:
#### XPath — also available in lxml, Scrapy, and browser's console via `'$x("<xpath>")'`:
```python
<xpath> = //<element>[/ or // <element>] # /<child>, //<descendant>, /../<siblng>
<xpath> = //<element>/following::<element> # Next element. Also preceding/parent/…
@ -2567,7 +2567,7 @@ def serve_html(sport):
return flask.render_template_string('<h1>{{title}}</h1>', title=sport)
```
* **Use `'render_template(filename, <kwargs>)'` to render file located in templates dir.**
* **To return an error code use `'abort(<int>)'` and to redirect use `'redirect("<url>")'`.**
* **To return an error code use `'abort(<int>)'` and to redirect use `'redirect(<url>)'`.**
* **`'request.args[<str>]'` returns parameter from the query string (URL part after '?').**
* **`'session[<str>] = <obj>'` stores session data. Needs `'app.secret_key = <str>'`.**

26
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>October 6, 2024</aside>
<aside>October 7, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -776,7 +776,7 @@ player = Player(point, direction) <span class="hljs-comment">#
<ul>
<li><strong>Potential problem with cache is that it can grow indefinitely. To clear the cache run <code class="python hljs"><span class="hljs-string">'fib.cache_clear()'</span></code> or use <code class="python hljs"><span class="hljs-string">'@functools.lru_cache(maxsize=&lt;int&gt;)'</span></code> instead.</strong></li>
<li><strong>Potential problem with cache is that it can grow indefinitely. To clear its stored values run <code class="python hljs"><span class="hljs-string">'fib.cache_clear()'</span></code>, or use <code class="python hljs"><span class="hljs-string">'@lru_cache(maxsize=&lt;int&gt;)'</span></code> decorator instead.</strong></li>
<li><strong>CPython interpreter limits recursion depth to 3000 by default. To increase it run <code class="python hljs"><span class="hljs-string">'sys.setrecursionlimit(&lt;int&gt;)'</span></code>.</strong></li>
</ul>
<div><h3 id="parametrizeddecorator">Parametrized Decorator</h3><p><strong>A decorator that accepts arguments and returns a normal decorator that accepts a function.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> wraps
@ -1605,14 +1605,14 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
</code></pre></div>
<pre><code class="text language-text">┏━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Dialect │ pip3 install │ import │ Dependencies ┃
┠────────────┼──────────────┼──────────┼──────────────────────────────────┨
┃ mysql │ mysqlclient │ MySQLdb │ www.pypi.org/project/mysqlclient ┃
┃ postgresql │ psycopg2 │ psycopg2 │ www.pypi.org/project/psycopg2 ┃
┃ mssql │ pyodbc │ pyodbc │ www.pypi.org/project/pyodbc ┃
┃ oracle │ oracledb │ oracledb │ www.pypi.org/project/oracledb ┃
┗━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
<pre><code class="text language-text">┏━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Dialect │ pip3 install │ Dependencies ┃
┠─────────────────┼──────────────┼──────────────────────────────────┨
┃ mysql │ mysqlclient │ www.pypi.org/project/mysqlclient ┃
┃ postgresql │ psycopg2 │ www.pypi.org/project/psycopg2 ┃
┃ mssql │ pyodbc │ www.pypi.org/project/pyodbc ┃
┃ oracle+oracledb │ oracledb │ www.pypi.org/project/oracledb ┃
┗━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
</code></pre>
<div><h2 id="bytes"><a href="#bytes" name="bytes">#</a>Bytes</h2><p><strong>A bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.</strong></p><pre><code class="python language-python hljs">&lt;bytes&gt; = <span class="hljs-string">b'&lt;str&gt;'</span> <span class="hljs-comment"># Only accepts ASCII characters and \x00-\xff.</span>
&lt;int&gt; = &lt;bytes&gt;[index] <span class="hljs-comment"># Returns an int in range from 0 to 255.</span>
@ -2072,7 +2072,7 @@ print(<span class="hljs-string">f'<span class="hljs-subst">{python_url}</span>,
</code></pre></div>
<div><h4 id="xpathalsoavailableinlxmlscrapyandbrowsersconsoleviadxxpath">XPath — also available in lxml, Scrapy, and browser's console via <code class="python hljs"><span class="hljs-string">'$x(&lt;xpath&gt;)'</span></code>:</h4><pre><code class="python language-python hljs">&lt;xpath&gt; = //&lt;element&gt;[/ <span class="hljs-keyword">or</span> // &lt;element&gt;] <span class="hljs-comment"># /&lt;child&gt;, //&lt;descendant&gt;, /../&lt;siblng&gt;</span>
<div><h4 id="xpathalsoavailableinlxmlscrapyandbrowsersconsoleviadxxpath">XPath — also available in lxml, Scrapy, and browser's console via <code class="python hljs"><span class="hljs-string">'$x("&lt;xpath&gt;")'</span></code>:</h4><pre><code class="python language-python hljs">&lt;xpath&gt; = //&lt;element&gt;[/ <span class="hljs-keyword">or</span> // &lt;element&gt;] <span class="hljs-comment"># /&lt;child&gt;, //&lt;descendant&gt;, /../&lt;siblng&gt;</span>
&lt;xpath&gt; = //&lt;element&gt;/following::&lt;element&gt; <span class="hljs-comment"># Next element. Also preceding/parent/…</span>
&lt;element&gt; = &lt;tag&gt;&lt;conditions&gt;&lt;index&gt; <span class="hljs-comment"># `&lt;tag&gt; = */a/…`, `&lt;index&gt; = [1/2/…]`.</span>
&lt;condition&gt; = [&lt;sub_cond&gt; [<span class="hljs-keyword">and</span>/<span class="hljs-keyword">or</span> &lt;sub_cond&gt;]] <span class="hljs-comment"># For negation use `not(&lt;sub_cond&gt;)`.</span>
@ -2106,7 +2106,7 @@ app.run(host=<span class="hljs-keyword">None</span>, port=<span class="hljs-keyw
<ul>
<li><strong>Use <code class="python hljs"><span class="hljs-string">'render_template(filename, &lt;kwargs&gt;)'</span></code> to render file located in templates dir.</strong></li>
<li><strong>To return an error code use <code class="python hljs"><span class="hljs-string">'abort(&lt;int&gt;)'</span></code> and to redirect use <code class="python hljs"><span class="hljs-string">'redirect("&lt;url&gt;")'</span></code>.</strong></li>
<li><strong>To return an error code use <code class="python hljs"><span class="hljs-string">'abort(&lt;int&gt;)'</span></code> and to redirect use <code class="python hljs"><span class="hljs-string">'redirect(&lt;url&gt;)'</span></code>.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'request.args[&lt;str&gt;]'</span></code> returns parameter from the query string (URL part after '?').</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'session[&lt;str&gt;] = &lt;obj&gt;'</span></code> stores session data. Needs <code class="python hljs"><span class="hljs-string">'app.secret_key = &lt;str&gt;'</span></code>.</strong></li>
</ul>
@ -2928,7 +2928,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active
<footer>
<aside>October 6, 2024</aside>
<aside>October 7, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

24
parse.js

@ -500,19 +500,19 @@ const DIAGRAM_9_B =
"┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n";
const DIAGRAM_95_A =
'+------------+--------------+----------+----------------------------------+\n' +
'| Dialect | pip3 install | import | Dependencies |\n' +
'+------------+--------------+----------+----------------------------------+\n';
'+-----------------+--------------+----------------------------------+\n' +
'| Dialect | pip3 install | Dependencies |\n' +
'+-----------------+--------------+----------------------------------+\n';
const DIAGRAM_95_B =
'┏━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n' +
'┃ Dialect │ pip3 install │ import │ Dependencies ┃\n' +
'┠────────────┼──────────────┼──────────┼──────────────────────────────────┨\n' +
'┃ mysql │ mysqlclient │ MySQLdb │ www.pypi.org/project/mysqlclient ┃\n' +
'┃ postgresql │ psycopg2 │ psycopg2 │ www.pypi.org/project/psycopg2 ┃\n' +
'┃ mssql │ pyodbc │ pyodbc │ www.pypi.org/project/pyodbc ┃\n' +
'┃ oracle │ oracledb │ oracledb │ www.pypi.org/project/oracledb ┃\n' +
'┗━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n';
'┏━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n' +
'┃ Dialect │ pip3 install │ Dependencies ┃\n' +
'┠─────────────────┼──────────────┼──────────────────────────────────┨\n' +
'┃ mysql │ mysqlclient │ www.pypi.org/project/mysqlclient ┃\n' +
'┃ postgresql │ psycopg2 │ www.pypi.org/project/psycopg2 ┃\n' +
'┃ mssql │ pyodbc │ www.pypi.org/project/pyodbc ┃\n' +
'┃ oracle+oracledb │ oracledb │ www.pypi.org/project/oracledb ┃\n' +
'┗━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n';
const DIAGRAM_10_A =
'+-------------+-------------+\n' +
@ -838,7 +838,7 @@ function fixClasses() {
function fixHighlights() {
$(`code:contains(<int> = ±0b<bin>)`).html(BIN_HEX);
$(`code:contains(@cache)`).html(CACHE);
$(`code:contains( + fib(n)`).html(CACHE);
$(`code:contains(@debug(print_result=True))`).html(PARAMETRIZED_DECORATOR);
$(`code:contains(print/str/repr([<obj>]))`).html(REPR_USE_CASES);
$(`code:contains((self, a=None):)`).html(CONSTRUCTOR_OVERLOADING);

Loading…
Cancel
Save