Skip to content

Commit 2bdf7f5

Browse files
committed
Exceptions
1 parent 7ac080b commit 2bdf7f5

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,18 @@ BaseException
14071407
+-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails.
14081408
```
14091409

1410+
#### Collections and their execeptions:
1411+
```python
1412+
+-----------+------------+----------+----------+
1413+
| | list | dict | set |
1414+
+-----------+------------+----------+----------+
1415+
| getitem() | IndexError | KeyError | |
1416+
| pop() | IndexError | KeyError | KeyError |
1417+
| remove() | ValueError | | KeyError |
1418+
| index() | ValueError | | |
1419+
+-----------+------------+----------+----------+
1420+
```
1421+
14101422
### User-defined Exceptions
14111423
```python
14121424
class MyError(Exception):
@@ -1431,8 +1443,7 @@ print(<el_1>, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
14311443
>>> from pprint import pprint
14321444
>>> pprint(dir())
14331445
['__annotations__',
1434-
'__builtins__',
1435-
'__doc__', ...]
1446+
'__builtins__', ...]
14361447
```
14371448

14381449

@@ -1441,20 +1452,12 @@ Input
14411452
* **Reads a line from user input or pipe if present.**
14421453
* **Trailing newline gets stripped.**
14431454
* **Prompt string is printed to the standard output before reading input.**
1455+
* **Raises EOFError when user hits EOF or input stream gets exhausted.**
14441456

14451457
```python
14461458
<str> = input(prompt=None)
14471459
```
14481460

1449-
#### Prints lines until EOF:
1450-
```python
1451-
while True:
1452-
try:
1453-
print(input())
1454-
except EOFError:
1455-
break
1456-
```
1457-
14581461

14591462
Command Line Arguments
14601463
----------------------

index.html

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,16 @@
13091309
+-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails.
13101310
</code></pre></div>
13111311

1312+
<div><h4 id="collectionsandtheirexeceptions">Collections and their execeptions:</h4><pre><code class="python language-python hljs">+-----------+------------+----------+----------+
1313+
| | list | dict | set |
1314+
+-----------+------------+----------+----------+
1315+
| getitem() | IndexError | KeyError | |
1316+
| pop() | IndexError | KeyError | KeyError |
1317+
| remove() | ValueError | | KeyError |
1318+
| index() | ValueError | | |
1319+
+-----------+------------+----------+----------+
1320+
</code></pre></div>
1321+
13121322
<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>
13131323
<span class="hljs-keyword">pass</span>
13141324

@@ -1326,25 +1336,18 @@
13261336
<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
13271337
<span class="hljs-meta">&gt;&gt;&gt; </span>pprint(dir())
13281338
[<span class="hljs-string">'__annotations__'</span>,
1329-
<span class="hljs-string">'__builtins__'</span>,
1330-
<span class="hljs-string">'__doc__'</span>, ...]
1339+
<span class="hljs-string">'__builtins__'</span>, ...]
13311340
</code></pre></div>
13321341

13331342
<div><h2 id="input"><a href="#input" name="input">#</a>Input</h2><ul>
13341343
<li><strong>Reads a line from user input or pipe if present.</strong></li>
13351344
<li><strong>Trailing newline gets stripped.</strong></li>
13361345
<li><strong>Prompt string is printed to the standard output before reading input.</strong></li>
1346+
<li><strong>Raises EOFError when user hits EOF or input stream gets exhausted.</strong></li>
13371347
</ul><pre><code class="python language-python hljs">&lt;str&gt; = input(prompt=<span class="hljs-keyword">None</span>)
13381348
</code></pre></div>
13391349

13401350

1341-
<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>:
1342-
<span class="hljs-keyword">try</span>:
1343-
print(input())
1344-
<span class="hljs-keyword">except</span> EOFError:
1345-
<span class="hljs-keyword">break</span>
1346-
</code></pre></div>
1347-
13481351
<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
13491352
script_name = sys.argv[<span class="hljs-number">0</span>]
13501353
arguments = sys.argv[<span class="hljs-number">1</span>:]

web/script_2.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ const DIAGRAM_9_B =
162162
"┃ escapechar │ None │ None │ None ┃\n" +
163163
"┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n";
164164

165+
const DIAGRAM_10_A =
166+
'+-----------+------------+----------+----------+\n' +
167+
'| | list | dict | set |\n' +
168+
'+-----------+------------+----------+----------+\n';
169+
170+
const DIAGRAM_10_B =
171+
'┏━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
172+
'┃ │ list │ dict │ set ┃\n' +
173+
'┠───────────┼────────────┼──────────┼──────────┨\n' +
174+
'┃ getitem() │ IndexError │ KeyError │ ┃\n' +
175+
'┃ pop() │ IndexError │ KeyError │ KeyError ┃\n' +
176+
'┃ remove() │ ValueError │ │ KeyError ┃\n' +
177+
'┃ index() │ ValueError │ │ ┃\n' +
178+
'┗━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
179+
165180

166181
// isFontAvailable:
167182
(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')) {
176191
$(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B);
177192
$(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B);
178193
$(`code:contains(${DIAGRAM_9_A})`).html(DIAGRAM_9_B);
194+
$(`code:contains(${DIAGRAM_10_A})`).html(DIAGRAM_10_B);
179195
}
180196

181197
var isMobile = false;

0 commit comments

Comments
 (0)