Browse Source

Format

pull/135/head
Jure Šorn 2 years ago
parent
commit
d07ca15537
3 changed files with 13 additions and 22 deletions
  1. 5
      README.md
  2. 4
      index.html
  3. 26
      parse.js

5
README.md

@ -398,7 +398,8 @@ Format
### Attributes
```python
>>> Person = collections.namedtuple('Person', 'name height')
>>> from collections import namedtuple
>>> Person = namedtuple('Person', 'name height')
>>> person = Person('Jean-Luc', 187)
>>> f'{person.height}'
'187'
@ -457,7 +458,9 @@ Format
| 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' |
| 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' |
+--------------+----------------+----------------+----------------+----------------+
```
```text
+--------------+----------------+----------------+----------------+----------------+
| | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |
+--------------+----------------+----------------+----------------+----------------+

4
index.html

@ -369,7 +369,8 @@ to_exclusive = &lt;range&gt;.stop
&lt;str&gt; = <span class="hljs-string">'%s, %s'</span> % (&lt;el_1&gt;, &lt;el_2&gt;) <span class="hljs-comment"># Redundant and inferior C style formatting.</span>
</code></pre></div>
<div><h3 id="attributes">Attributes</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>Person = collections.namedtuple(<span class="hljs-string">'Person'</span>, <span class="hljs-string">'name height'</span>)
<div><h3 id="attributes">Attributes</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> namedtuple
<span class="hljs-meta">&gt;&gt;&gt; </span>Person = namedtuple(<span class="hljs-string">'Person'</span>, <span class="hljs-string">'name height'</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>person = Person(<span class="hljs-string">'Jean-Luc'</span>, <span class="hljs-number">187</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-string">f'<span class="hljs-subst">{person.height}</span>'</span>
<span class="hljs-string">'187'</span>
@ -434,6 +435,7 @@ to_exclusive = &lt;range&gt;.stop
┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛
</code></pre></div>
<pre></pre>
<ul>
<li><strong>When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. That makes <code class="python hljs"><span class="hljs-string">'{6.5:.0f}'</span></code> a <code class="python hljs"><span class="hljs-string">'6'</span></code> and <code class="python hljs"><span class="hljs-string">'{7.5:.0f}'</span></code> an <code class="python hljs"><span class="hljs-string">'8'</span></code>.</strong></li>
<li><strong>This rule only effects numbers that can be represented exactly by a float (<code class="python hljs"><span class="hljs-number">.5</span></code>, <code class="python hljs"><span class="hljs-number">.25</span></code>, …).</strong></li>

26
parse.js

@ -112,15 +112,6 @@ const DIAGRAM_1_A =
'| | Iterable | Collection | Sequence |\n' +
'+------------------+------------+------------+------------+\n';
// const DIAGRAM_1_B =
// '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
// '┃ │ Sequence │ Collection │ Iterable ┃\n' +
// '┠──────────────────┼────────────┼────────────┼────────────┨\n' +
// '┃ list, range, str │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ dict, set │ │ ✓ │ ✓ ┃\n' +
// '┃ iter │ │ │ ✓ ┃\n' +
// '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
const DIAGRAM_1_B =
'┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
'┃ │ Iterable │ Collection │ Sequence ┃\n' +
@ -135,17 +126,6 @@ const DIAGRAM_2_A =
'| | Number | Complex | Real | Rational | Integral |\n' +
'+--------------------+----------+----------+----------+----------+----------+\n';
// const DIAGRAM_2_B =
// '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
// '┃ │ Integral │ Rational │ Real │ Complex │ Number ┃\n' +
// '┠────────────────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
// '┃ int │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ fractions.Fraction │ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ float │ │ │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ complex │ │ │ │ ✓ │ ✓ ┃\n' +
// '┃ decimal.Decimal │ │ │ │ │ ✓ ┃\n' +
// '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
const DIAGRAM_2_B =
'┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
'┃ │ Number │ Complex │ Real │ Rational │ Integral ┃\n' +
@ -201,6 +181,11 @@ const DIAGRAM_4_B =
"┃ 56.789 │ '5.7e+01' │ '56.79' │ '5.68e+01' │ '5678.90%' ┃\n" +
"┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛\n";
const DIAGRAM_5_A =
"+--------------+----------------+----------------+----------------+----------------+\n" +
"| | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |\n" +
"+--------------+----------------+----------------+----------------+----------------+\n";
const DIAGRAM_6_A =
'+------------+------------+------------+------------+--------------+\n' +
'| | Iterable | Collection | Sequence | abc.Sequence |\n' +
@ -530,6 +515,7 @@ function updateDiagrams() {
$(`code:contains(${DIAGRAM_2_A})`).html(DIAGRAM_2_B);
$(`code:contains(${DIAGRAM_3_A})`).html(DIAGRAM_3_B);
$(`code:contains(${DIAGRAM_4_A})`).html(DIAGRAM_4_B);
$(`code:contains(${DIAGRAM_5_A})`).remove();
$(`code:contains(${DIAGRAM_6_A})`).html(DIAGRAM_6_B);
$(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B);
$(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B);

Loading…
Cancel
Save