Skip to content

Commit da732c9

Browse files
start refining debugging
1 parent ee65738 commit da732c9

File tree

5 files changed

+49
-32
lines changed

5 files changed

+49
-32
lines changed

book/061_dependencies.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"id": "c79acc5e-0543-4994-b09a-1af21a509cd2",
1717
"metadata": {},
1818
"source": [
19-
"In contrast to the code that we ourselves write and can import or to some built-in modules such as `pathlib` and `json` that we can import directly after installing python, there are third-party libraries that we want to use but need to be first installed, such as `numpy` and `pandas`. \n",
19+
"In contrast to our own code that we can import or to some built-in modules such as `pathlib` that we can import directly after installing python, there are third-party libraries that we want to use but need to be first installed, such as `numpy` and `pandas`.\n",
2020
"This libraries are also called \"packages\".\n",
21-
"There are several repositories where people publish python packages and from which we can download them, but the official one is [PyPI](https://pypi.org) (Python Package Index).\n",
2221
"\n",
22+
"There are several repositories (also called \"indexes\") where people publish python packages and from which we can download them. The official one is [PyPI](https://pypi.org) (Python Package Index).\n",
2323
"\n",
2424
"These are open-source libraries maintained mostly by voluntary contributions of people of the community – and you can also contribute to them!\n",
2525
"\n",
26-
"They are being actively developed and thus in permanent evolution.\n",
26+
"These packages are being actively developed and thus in permanent evolution.\n",
2727
"In order to avoid compatibility problems and to ensure reproducibility, we might want to specify the exact versions of the packages we use.\n",
2828
"It turns out that is not an easy problem and the reason why need a **package manager**.\n",
2929
"\n",
@@ -110,6 +110,8 @@
110110
"That will add the dependency to our list as well as updating the \"lock\" file.\n",
111111
"Read more about this workflow and managing dependencies [here](https://docs.astral.sh/uv/guides/projects/#working-on-projects).\n",
112112
"\n",
113+
"The point is that after installing the dependency we can just import it like any other module.\n",
114+
"\n",
113115
"To remove a package from the dependencies of our project we do:\n",
114116
"```bash\n",
115117
"uv remove PACKAGE-NAME\n",
@@ -121,11 +123,9 @@
121123
]
122124
},
123125
{
124-
"cell_type": "code",
125-
"execution_count": null,
126-
"id": "c32b1f81-3a46-460c-b537-4cd56b1e49b0",
126+
"cell_type": "markdown",
127+
"id": "64fc1a40-04fe-40da-8875-04e4aa5d4d46",
127128
"metadata": {},
128-
"outputs": [],
129129
"source": []
130130
}
131131
],

book/06_imports.ipynb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,19 @@
156156
"id": "3b452c0b-682f-4868-9fd6-4dc6f7a5ff69",
157157
"metadata": {},
158158
"source": [
159-
"## Script vs. Importable Code\n",
160-
"We can also import code that we wrote ourselves with the same syntax.\n",
161-
"For example, if we have a python file called `mymodule.py` we can import it from another file with:\n",
159+
"## Importable Code vs. Scripting\n",
160+
"We can also import our own code.\n",
161+
"For example, if we have a python file called `mymodule.py` we can use it in another file:\n",
162162
"\n",
163163
"```python\n",
164+
"# anotherfile.py\n",
165+
"\n",
164166
"import mymodule\n",
165167
"```\n",
166168
"\n",
167-
"A Python module (any `.py` file) might contain code that we want to run as a script alongside code that we only want to use somewhere else (importing parts of it).\n",
169+
"Sometimes we have a Python module (any `.py` file) that contain code that we only want to run as a script alongside code that we only want to use somewhere else (importing parts of it).\n",
168170
"\n",
169-
"We can isolate part of the code that we want to run as a script with a trick that's easier to show than to explain, so let's do some exercises."
171+
"We can isolate part of the code that we want to run as a script with a special syntax, let's do some exercises to show it."
170172
]
171173
},
172174
{
@@ -181,11 +183,13 @@
181183
"\n",
182184
"```python\n",
183185
"# data.py\n",
186+
"\n",
184187
"RAWDATA = ... # 3 dots are called \"Ellipsis\" and act as placeholder\n",
185188
"\n",
186189
"def fetch_data(raw_data):\n",
187190
" ... \n",
188191
"\n",
192+
"# This block will only run when calling `python data.py`\n",
189193
"if __name__ == \"__main__\":\n",
190194
" print(\"Fetching data\") \n",
191195
" data = fetch_data(RAWDATA)\n",

book/111_debugging.ipynb

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,50 @@
1212
]
1313
},
1414
{
15-
"cell_type": "code",
16-
"execution_count": null,
17-
"id": "3d0080c9-01ad-4120-ad3d-37700cdf2a6f",
15+
"cell_type": "markdown",
16+
"id": "bd498d45-9d1e-4860-854b-a94993ffa77b",
1817
"metadata": {},
19-
"outputs": [],
2018
"source": [
21-
"🚧\n",
22-
"Material under construction\n",
23-
"🚧"
19+
"We are humans, we make mistakes – that's very much true for coding.\n",
20+
"Finding errors in our code is fundamental skill to train.\n",
21+
"\n",
22+
"We will cover here a few tools that help us find and fix errors more quickly."
2423
]
2524
},
2625
{
2726
"cell_type": "markdown",
28-
"id": "bd498d45-9d1e-4860-854b-a94993ffa77b",
27+
"id": "3789894a-e176-4cc5-872a-c328b66b1359",
2928
"metadata": {},
3029
"source": [
31-
"We are humans, we make mistakes and that's very much true for coding.\n",
32-
"Finding errors in our code is fundamental skill to train since we cannot avoid making mistakes.\n",
33-
"The goal is to get better at finding and fixing them quickly."
30+
"## What is a debugger?\n",
31+
"\n",
32+
"A debugger is a device that allows us to interrupt code execution and jump into the execution context in a interactive mode, so that we can inspect and run code to find out what's going on. \n",
33+
"We called that to \"set a breakpoint\" or \"set a trace\".\n",
34+
"\n",
35+
"There are a few options to do that natively in python."
3436
]
3537
},
3638
{
3739
"cell_type": "markdown",
3840
"id": "55a9413f-5a5a-40c1-a2b7-b642f0a54aec",
3941
"metadata": {},
4042
"source": [
41-
"## Python debugger, breakpoints"
43+
"## Python debugger, breakpoints\n",
44+
"The python standard library includes `pdb` module.\n",
45+
"\n",
46+
"```python\n",
47+
"import pdb; pdb.set_trace()\n",
48+
"```"
4249
]
4350
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"id": "b40ea608-89a9-4cbd-b07f-4f9a33699d89",
55+
"metadata": {},
56+
"outputs": [],
57+
"source": []
58+
},
4459
{
4560
"cell_type": "markdown",
4661
"id": "4ae14f36-84e6-4def-9240-7a423c587e9c",
@@ -74,7 +89,7 @@
7489
"name": "python",
7590
"nbconvert_exporter": "python",
7691
"pygments_lexer": "ipython3",
77-
"version": "3.10.13"
92+
"version": "3.13.3"
7893
}
7994
},
8095
"nbformat": 4,

book/_quarto.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ book:
4545
- 062_read_and_write.ipynb
4646
- 061_dependencies.ipynb
4747
- 063_common_data_formats.ipynb
48-
- 051_oop.ipynb
48+
- 111_debugging.ipynb
4949
- 08_numpy.ipynb
5050
- 081_pandas.ipynb
5151
- 09_plotting.ipynb
5252
- 10_tests.ipynb
5353
- 11_cli.ipynb
54-
- 111_debugging.ipynb
5554
- 13_tools.ipynb
55+
- 051_oop.ipynb
5656
- lab_explore_data_exercises.ipynb
5757
- notebook_workflow.ipynb
5858
- 999_glossary.ipynb

book/index.qmd

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ This is a free, **short introduction** to the Python programming language, empha
33
The goal is to get you just enough tools under your belt for you to pursue your own learning path according to your interests.
44
What's in for you:
55

6-
76
✅ Core concepts of the language explained in _simple words_
8-
✅ Focus on "data-stack" ([numpy](https://numpy.org), [pandas](https://pandas.pydata.org/), [matplotlib](https://matplotlib.org/), etc.)
97
✅ Software engineering best-practices (project/dependency management, [`uv`](https://docs.astral.sh/uv/), testing with [pytest](https://docs.pytest.org/en/stable/), error handling, etc.)
10-
✅ Exercises on each chapter to get comfortable with the new concepts
11-
✅ Integrative "Labs" with real-world datasets to put all concepts together
128
✅ Useful references to deepen your knowledge (talks, books, cheatsheets, etc.)
9+
✅ Exercises for each chapter to ramp up your skills with deliberate practice
10+
✅ Integrative "Labs" with real-world datasets
1311

1412
Code notebooks and report any problems on [this GitHub repository](https://www.github.com/fabridamicelli/python-course).
1513

@@ -18,6 +16,6 @@ Off we go! 🚀
1816

1917
# About the Author
2018
Fabrizio Damicelli (PhD, Computational Neuroscience) is a self-taught coder who prefers solid intuitions to unnecessary sophistication and fancy jargon.
21-
Open source advocate, creator and maintainer of a few of Python packages.
19+
Open source advocate, creator and maintainer of a few of Python packages and Open Source projects.
2220
Learn more about him [here](https://fabridamicelli.github.io).
2321

0 commit comments

Comments
 (0)