Skip to content

Commit 3e497ee

Browse files
committed
Use ipython friendly debugging
1 parent 5f305d7 commit 3e497ee

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

notebooks/beginner/exercises/14_debugging_exercise.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"source": [
1919
"def stripped_reversed_lowercase(original):\n",
2020
" # Set a breakpoint here and start debugging\n",
21+
" # from IPython.core.debugger import Pdb; Pdb().set_trace()\n",
2122
" stripped = original.lstrip()\n",
2223
" reversed = \" \".join(reversed(stripped))\n",
2324
" reversed.lower()\n",
@@ -55,7 +56,7 @@
5556
"name": "python",
5657
"nbconvert_exporter": "python",
5758
"pygments_lexer": "ipython3",
58-
"version": "3.10.3"
59+
"version": "3.11.0"
5960
}
6061
},
6162
"nbformat": 4,

notebooks/beginner/notebooks/14_debugging.ipynb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"cell_type": "markdown",
1313
"metadata": {},
1414
"source": [
15-
"## `import pdb; pdb.set_trace()`\n",
16-
"The basic use case for debugging is that you want to stop the execution of your program at some certain point and monitor variable values or program execution in general from that specific point onward. You stop the execution at the point you want by setting a breakpoint into code by `import pdb; pdb.set_trace()` (note in Python versions >= 3.7, there's a shortcut: `breakpoint()`).\n",
15+
"## `breakpoint()`\n",
16+
"The basic use case for debugging is that you want to stop the execution of your program at some certain point and monitor variable values or program execution in general from that specific point onward. You stop the execution at the point you want by setting a breakpoint into code by `breakpoint()`.\n",
1717
"\n",
1818
"When you execute your program, the execution will stop at this point and will enter to interactive debugger session. You can add as many breakpoints into your code as you want."
1919
]
@@ -41,7 +41,7 @@
4141
"metadata": {},
4242
"source": [
4343
"## Let's see how it works\n",
44-
"Uncomment the `import pdb; pdb.set_trace()` lines and execute the cell. Execute the program line by line by using the commands defined above. Try all the above mentioned commands at least once. Pay attention to the difference between `n` and `s`."
44+
"Uncomment the `Pdb().set_trace()` (this is the Jupyter notebook equivalent for `breakpoint()`) lines and execute the cell. Execute the program line by line by using the commands defined above. Try all the above mentioned commands at least once. Pay attention to the difference between `n` and `s`."
4545
]
4646
},
4747
{
@@ -50,6 +50,9 @@
5050
"metadata": {},
5151
"outputs": [],
5252
"source": [
53+
"from IPython.core.debugger import Pdb\n",
54+
"\n",
55+
"\n",
5356
"class SuperGreeter:\n",
5457
" def __init__(self, people_to_greet):\n",
5558
" self.people = people_to_greet\n",
@@ -68,7 +71,7 @@
6871
" print(greeting)\n",
6972
"\n",
7073
" def _greet_street_style(self, name):\n",
71-
" # import pdb; pdb.set_trace() # UNCOMMENT\n",
74+
" # Pdb().set_trace() # UNCOMMENT\n",
7275
" name = name.upper()\n",
7376
" print(f\"WASSUP {name}!?\")\n",
7477
"\n",
@@ -78,7 +81,7 @@
7881
"\n",
7982
"def main():\n",
8083
" people = [\"John Doe\", \"Donald\", \"Lisa\", \"alex\"]\n",
81-
" # import pdb; pdb.set_trace() # UNCOMMENT\n",
84+
" # Pdb().set_trace() # UNCOMMENT\n",
8285
" greeter = SuperGreeter(people)\n",
8386
" greeter.greet()\n",
8487
"\n",
@@ -89,7 +92,7 @@
8992
],
9093
"metadata": {
9194
"kernelspec": {
92-
"display_name": "Python 3",
95+
"display_name": "Python 3 (ipykernel)",
9396
"language": "python",
9497
"name": "python3"
9598
},
@@ -103,7 +106,7 @@
103106
"name": "python",
104107
"nbconvert_exporter": "python",
105108
"pygments_lexer": "ipython3",
106-
"version": "3.5.4"
109+
"version": "3.11.0"
107110
}
108111
},
109112
"nbformat": 4,

0 commit comments

Comments
 (0)