Skip to content

Commit

Permalink
Exceptions - Revisions
Browse files Browse the repository at this point in the history
Added material to give further explanation for beginning programmers.
  • Loading branch information
d-s-1 committed Sep 1, 2017
1 parent 4bb66fd commit dbc9fbe
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Observe that a `NameError` is raised and also the location where the error was d

## Exceptions

We will **try** to read input from the user. Press `[ctrl-d]`, (or `[ctrl-z]` if you are using Windows), and see what happens.
We will **try** to read input from the user. Enter the first line below and hit the `Enter` key. When your computer prompts you for input, instead press `[ctrl-d]` on a Mac or `[ctrl-z]` with Windows and see what happens. (If you're using Windows and neither option works, you can try `[ctrl-c]` in the Command Prompt to generate a KeyboardInterrupt error instead).

```python
>>> s = input('Enter something --> ')
Expand Down Expand Up @@ -94,7 +94,9 @@ We do the usual file-reading stuff, but we have arbitrarily introduced sleeping

Observe that the `KeyboardInterrupt` exception is thrown and the program quits. However, before the program exits, the finally clause is executed and the file object is always closed.

Note that we use `sys.stdout.flush()` after `print` so that it prints to the screen immediately.
Notice that a variable assigned a value of 0 or `None` or a variable which is an empty sequence or collection is considered `False` by Python. This is why we can use `if: f` in the code above.

Also note that we use `sys.stdout.flush()` after `print` so that it prints to the screen immediately.

## The with statement {#with}

Expand Down

0 comments on commit dbc9fbe

Please sign in to comment.