Browse Source

Exceptions

pull/42/head
Jure Šorn 5 years ago
parent
commit
2bdf7f54a8
3 changed files with 42 additions and 20 deletions
  1. 25
      README.md
  2. 21
      index.html
  3. 16
      web/script_2.js

25
README.md

@ -1407,6 +1407,18 @@ BaseException
+-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails. +-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails.
``` ```
#### Collections and their execeptions:
```python
+-----------+------------+----------+----------+
| | list | dict | set |
+-----------+------------+----------+----------+
| getitem() | IndexError | KeyError | |
| pop() | IndexError | KeyError | KeyError |
| remove() | ValueError | | KeyError |
| index() | ValueError | | |
+-----------+------------+----------+----------+
```
### User-defined Exceptions ### User-defined Exceptions
```python ```python
class MyError(Exception): class MyError(Exception):
@ -1431,8 +1443,7 @@ print(<el_1>, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
>>> from pprint import pprint >>> from pprint import pprint
>>> pprint(dir()) >>> pprint(dir())
['__annotations__', ['__annotations__',
'__builtins__',
'__doc__', ...]
'__builtins__', ...]
``` ```
@ -1441,20 +1452,12 @@ Input
* **Reads a line from user input or pipe if present.** * **Reads a line from user input or pipe if present.**
* **Trailing newline gets stripped.** * **Trailing newline gets stripped.**
* **Prompt string is printed to the standard output before reading input.** * **Prompt string is printed to the standard output before reading input.**
* **Raises EOFError when user hits EOF or input stream gets exhausted.**
```python ```python
<str> = input(prompt=None) <str> = input(prompt=None)
``` ```
#### Prints lines until EOF:
```python
while True:
try:
print(input())
except EOFError:
break
```
Command Line Arguments Command Line Arguments
---------------------- ----------------------

21
index.html

@ -1309,6 +1309,16 @@ LogicOp = Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-st
+-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails. +-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails.
</code></pre></div> </code></pre></div>
<div><h4 id="collectionsandtheirexeceptions">Collections and their execeptions:</h4><pre><code class="python language-python hljs">+-----------+------------+----------+----------+
| | list | dict | set |
+-----------+------------+----------+----------+
| getitem() | IndexError | KeyError | |
| pop() | IndexError | KeyError | KeyError |
| remove() | ValueError | | KeyError |
| index() | ValueError | | |
+-----------+------------+----------+----------+
</code></pre></div>
<div><h3 id="userdefinedexceptions">User-defined Exceptions</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyError</span><span class="hljs-params">(Exception)</span>:</span> <div><h3 id="userdefinedexceptions">User-defined Exceptions</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyError</span><span class="hljs-params">(Exception)</span>:</span>
<span class="hljs-keyword">pass</span> <span class="hljs-keyword">pass</span>
@ -1326,25 +1336,18 @@ LogicOp = Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-st
<div><h3 id="prettyprint">Pretty Print</h3><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 <div><h3 id="prettyprint">Pretty Print</h3><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
<span class="hljs-meta">&gt;&gt;&gt; </span>pprint(dir()) <span class="hljs-meta">&gt;&gt;&gt; </span>pprint(dir())
[<span class="hljs-string">'__annotations__'</span>, [<span class="hljs-string">'__annotations__'</span>,
<span class="hljs-string">'__builtins__'</span>,
<span class="hljs-string">'__doc__'</span>, ...]
<span class="hljs-string">'__builtins__'</span>, ...]
</code></pre></div> </code></pre></div>
<div><h2 id="input"><a href="#input" name="input">#</a>Input</h2><ul> <div><h2 id="input"><a href="#input" name="input">#</a>Input</h2><ul>
<li><strong>Reads a line from user input or pipe if present.</strong></li> <li><strong>Reads a line from user input or pipe if present.</strong></li>
<li><strong>Trailing newline gets stripped.</strong></li> <li><strong>Trailing newline gets stripped.</strong></li>
<li><strong>Prompt string is printed to the standard output before reading input.</strong></li> <li><strong>Prompt string is printed to the standard output before reading input.</strong></li>
<li><strong>Raises EOFError when user hits EOF or input stream gets exhausted.</strong></li>
</ul><pre><code class="python language-python hljs">&lt;str&gt; = input(prompt=<span class="hljs-keyword">None</span>) </ul><pre><code class="python language-python hljs">&lt;str&gt; = input(prompt=<span class="hljs-keyword">None</span>)
</code></pre></div> </code></pre></div>
<div><h4 id="printslinesuntileof">Prints lines until EOF:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>:
<span class="hljs-keyword">try</span>:
print(input())
<span class="hljs-keyword">except</span> EOFError:
<span class="hljs-keyword">break</span>
</code></pre></div>
<div><h2 id="commandlinearguments"><a href="#commandlinearguments" name="commandlinearguments">#</a>Command Line Arguments</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sys <div><h2 id="commandlinearguments"><a href="#commandlinearguments" name="commandlinearguments">#</a>Command Line Arguments</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sys
script_name = sys.argv[<span class="hljs-number">0</span>] script_name = sys.argv[<span class="hljs-number">0</span>]
arguments = sys.argv[<span class="hljs-number">1</span>:] arguments = sys.argv[<span class="hljs-number">1</span>:]

16
web/script_2.js

@ -162,6 +162,21 @@ const DIAGRAM_9_B =
"┃ escapechar │ None │ None │ None ┃\n" + "┃ escapechar │ None │ None │ None ┃\n" +
"┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n"; "┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n";
const DIAGRAM_10_A =
'+-----------+------------+----------+----------+\n' +
'| | list | dict | set |\n' +
'+-----------+------------+----------+----------+\n';
const DIAGRAM_10_B =
'┏━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
'┃ │ list │ dict │ set ┃\n' +
'┠───────────┼────────────┼──────────┼──────────┨\n' +
'┃ getitem() │ IndexError │ KeyError │ ┃\n' +
'┃ pop() │ IndexError │ KeyError │ KeyError ┃\n' +
'┃ remove() │ ValueError │ │ KeyError ┃\n' +
'┃ index() │ ValueError │ │ ┃\n' +
'┗━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
// isFontAvailable: // isFontAvailable:
(function(d){function c(c){b.style.fontFamily=c;e.appendChild(b);f=b.clientWidth;e.removeChild(b);return f}var f,e=d.body,b=d.createElement("span");b.innerHTML=Array(100).join("wi");b.style.cssText=["position:absolute","width:auto","font-size:128px","left:-99999px"].join(" !important;");var g=c("monospace"),h=c("serif"),k=c("sans-serif");window.isFontAvailable=function(b){return g!==c(b+",monospace")||k!==c(b+",sans-serif")||h!==c(b+",serif")}})(document); (function(d){function c(c){b.style.fontFamily=c;e.appendChild(b);f=b.clientWidth;e.removeChild(b);return f}var f,e=d.body,b=d.createElement("span");b.innerHTML=Array(100).join("wi");b.style.cssText=["position:absolute","width:auto","font-size:128px","left:-99999px"].join(" !important;");var g=c("monospace"),h=c("serif"),k=c("sans-serif");window.isFontAvailable=function(b){return g!==c(b+",monospace")||k!==c(b+",sans-serif")||h!==c(b+",serif")}})(document);
@ -176,6 +191,7 @@ if (isFontAvailable('Menlo')) {
$(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B); $(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B);
$(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B); $(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B);
$(`code:contains(${DIAGRAM_9_A})`).html(DIAGRAM_9_B); $(`code:contains(${DIAGRAM_9_A})`).html(DIAGRAM_9_B);
$(`code:contains(${DIAGRAM_10_A})`).html(DIAGRAM_10_B);
} }
var isMobile = false; var isMobile = false;

Loading…
Cancel
Save