You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ba924f5
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: lectures/debugging.md
+305-8Lines changed: 305 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ kernelspec:
18
18
</div>
19
19
```
20
20
21
-
# Debugging
21
+
# Debugging and Handling Errors
22
22
23
23
```{index} single: Debugging
24
24
```
@@ -43,9 +43,20 @@ Hey, we all used to do that.
43
43
44
44
But once you start writing larger programs you'll need a better system.
45
45
46
+
You may also want to handle potential errors in your code as they occur.
47
+
48
+
In this lecture, we will discuss how to debug our programs and improve error handling.
49
+
50
+
## Debugging
51
+
52
+
```{index} single: Debugging
53
+
```
54
+
46
55
Debugging tools for Python vary across platforms, IDEs and editors.
47
56
48
-
Here we'll focus on Jupyter and leave you to explore other settings.
57
+
For example, a [visual debugger](https://jupyterlab.readthedocs.io/en/stable/user/debugger.html) is available in JupyterLab.
58
+
59
+
Here we'll focus on Jupyter Notebook and leave you to explore other settings.
49
60
50
61
We'll need the following imports
51
62
@@ -56,11 +67,7 @@ import matplotlib.pyplot as plt
56
67
plt.rcParams['figure.figsize'] = (10,6)
57
68
```
58
69
59
-
## Debugging
60
-
61
-
```{index} single: Debugging
62
-
```
63
-
70
+
(debug_magic)=
64
71
### The `debug` Magic
65
72
66
73
Let's consider a simple (and rather contrived) example
@@ -243,7 +250,7 @@ Then we printed the value of `x` to see what was happening with that variable.
243
250
244
251
To exit from the debugger, use `q`.
245
252
246
-
## Other Useful Magics
253
+
###Other Useful Magics
247
254
248
255
In this lecture, we used the `%debug` IPython magic.
249
256
@@ -255,3 +262,293 @@ There are many other useful magics:
255
262
256
263
The full list of magics is [here](http://ipython.readthedocs.org/en/stable/interactive/magics.html).
257
264
265
+
266
+
## Handling Errors
267
+
268
+
```{index} single: Python; Handling Errors
269
+
```
270
+
271
+
Sometimes it's possible to anticipate bugs and errors as we're writing code.
272
+
273
+
For example, the unbiased sample variance of sample $y_1, \ldots, y_n$
0 commit comments