|
@ -798,6 +798,37 @@ LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r), |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Exceptions |
|
|
|
|
|
---------- |
|
|
|
|
|
```python |
|
|
|
|
|
while True: |
|
|
|
|
|
try: |
|
|
|
|
|
x = int(input('Please enter a number: ')) |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
print('Oops! That was no valid number. Try again...') |
|
|
|
|
|
else: |
|
|
|
|
|
print('Thank you.') |
|
|
|
|
|
break |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
#### Raising exception: |
|
|
|
|
|
```python |
|
|
|
|
|
raise ValueError('A very specific message!') |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### Finally |
|
|
|
|
|
```python |
|
|
|
|
|
>>> try: |
|
|
|
|
|
... raise KeyboardInterrupt |
|
|
|
|
|
... finally: |
|
|
|
|
|
... print('Goodbye, world!') |
|
|
|
|
|
Goodbye, world! |
|
|
|
|
|
Traceback (most recent call last): |
|
|
|
|
|
File "<stdin>", line 2, in <module> |
|
|
|
|
|
KeyboardInterrupt |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System |
|
|
System |
|
|
------ |
|
|
------ |
|
|
### Command Line Arguments |
|
|
### Command Line Arguments |
|
@ -988,37 +1019,6 @@ db.commit() |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Exceptions |
|
|
|
|
|
---------- |
|
|
|
|
|
```python |
|
|
|
|
|
while True: |
|
|
|
|
|
try: |
|
|
|
|
|
x = int(input('Please enter a number: ')) |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
print('Oops! That was no valid number. Try again...') |
|
|
|
|
|
else: |
|
|
|
|
|
print('Thank you.') |
|
|
|
|
|
break |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
#### Raising exception: |
|
|
|
|
|
```python |
|
|
|
|
|
raise ValueError('A very specific message!') |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### Finally |
|
|
|
|
|
```python |
|
|
|
|
|
>>> try: |
|
|
|
|
|
... raise KeyboardInterrupt |
|
|
|
|
|
... finally: |
|
|
|
|
|
... print('Goodbye, world!') |
|
|
|
|
|
Goodbye, world! |
|
|
|
|
|
Traceback (most recent call last): |
|
|
|
|
|
File "<stdin>", line 2, in <module> |
|
|
|
|
|
KeyboardInterrupt |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bytes |
|
|
Bytes |
|
|
----- |
|
|
----- |
|
|
**Bytes object is immutable sequence of single bytes. Mutable version is called bytearray.** |
|
|
**Bytes object is immutable sequence of single bytes. Mutable version is called bytearray.** |
|
|