From 33372709b3a6b265439e9e97b38ab470658b8534 Mon Sep 17 00:00:00 2001 From: mmcky Date: Tue, 12 Dec 2023 14:17:23 +1100 Subject: [PATCH] mmcky edits --- lectures/getting_started.md | 18 ++++++++++++++---- lectures/workspace.md | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lectures/getting_started.md b/lectures/getting_started.md index 905d1356..b9bff5d7 100644 --- a/lectures/getting_started.md +++ b/lectures/getting_started.md @@ -384,6 +384,9 @@ Now we `Shift+Enter` to produce this ### Debugging Code +```{index} single: Jupyter Notebook; Debugging +``` + Debugging is the process of identifying and removing errors from a program. You will spend a lot of time debugging code, so it is important to [learn how to do it effectively](https://www.freecodecamp.org/news/what-is-debugging-how-to-debug-code/). @@ -391,23 +394,29 @@ You will spend a lot of time debugging code, so it is important to [learn how to If you are using a newer version of Jupyter, you should see a bug icon on the right end of the toolbar. ```{figure} /_static/lecture_specific/getting_started/debug.png +:scale: 80% :figclass: auto ``` + Clicking this icon will enable the Jupyter debugger. -You would also need to open the Debugger Panel (View -> Debugger Panel). + +```{note} +You may also need to open the Debugger Panel (View -> Debugger Panel). +``` You can set breakpoints by clicking on the line number of the cell you want to debug. When you run the cell, the debugger will stop at the breakpoint. -You can then step through the code line by line using the buttons on the "Next" button on the Callstack toolbar. +You can then step through the code line by line using the buttons on the "Next" button on the CALLSTACK toolbar (located in the right hand window). + ```{figure} /_static/lecture_specific/getting_started/debugger_breakpoint.png :figclass: auto ``` -You can explore the functionality of the debugger in detail at the [documentation](https://jupyterlab.readthedocs.io/en/latest/user/debugger.html). +You can explore more functionality of the debugger in the [Jupyter documentation](https://jupyterlab.readthedocs.io/en/latest/user/debugger.html). ### Sharing Notebooks @@ -430,7 +439,8 @@ Save it somewhere, navigate to it from the Jupyter dashboard and then run as dis ```{note} If you are interested in sharing notebooks containing interactive content, you might want to check out [Binder](https://mybinder.org/). -To collaborate with other people on notebooks, you might want to check out +To collaborate with other people on notebooks, you might want to take a look at + - [Google Colab](https://colab.research.google.com/) - [Kaggle](https://www.kaggle.com/kernels) diff --git a/lectures/workspace.md b/lectures/workspace.md index 5ff095b0..7cdbf190 100644 --- a/lectures/workspace.md +++ b/lectures/workspace.md @@ -20,7 +20,6 @@ kernelspec: # Writing Longer Programs - ```{contents} Contents :depth: 2 ``` @@ -30,7 +29,9 @@ So far, we have explored the use of Jupyter Notebooks in writing and executing P While they are efficient and adaptable when working with short pieces of code, Notebooks are not the best choice for longer programs and scripts. -Jupyter Notebooks are well suited to interactive computing (i.e. data science workflows) and can help execute chunks of code one at a time. Text files and scripts allow for long pieces of code to be written and executed in a single go. +Jupyter Notebooks are well suited to interactive computing (i.e. data science workflows) and can help execute chunks of code one at a time. + +Text files and scripts allow for long pieces of code to be written and executed in a single go. We will explore the use of Python scripts as an alternative. @@ -49,11 +50,10 @@ You may want to [create a new conda environment](https://conda.io/projects/conda ## Working with Python files -Python files are used when writing long, reusable blocks of code - by convention, they have a ```.py``` suffix. +Python files are used when writing long, reusable blocks of code - by convention, they have a `.py` suffix. Let us begin by working with the following example. - ```{code-block} python :caption: sine_wave.py :lineno-start: 1 @@ -107,7 +107,7 @@ import sine_wave # Import the sine_wave script sine_wave.plot_wave("Sine Wave - Called from the Second Script") ``` -This allows you to split your code into chuncks and structure your codebase better. +This allows you to split your code into chunks and structure your codebase better. Look into the use of [modules](https://docs.python.org/3/tutorial/modules.html) and [packages](https://docs.python.org/3/tutorial/modules.html#packages) for more information on importing functionality. @@ -176,9 +176,9 @@ Coming back to the example scripts from earlier, there are two ways to work with ### Using magic commands -Jupyter Notebooks and JupyterLab support the use of [magic commands](https://ipython.readthedocs.io/en/stable/interactive/magics.html) - commands that extend the capabilites of a standard Jupyter Notebook. +Jupyter Notebooks and JupyterLab support the use of [magic commands](https://ipython.readthedocs.io/en/stable/interactive/magics.html) - commands that extend the capabilities of a standard Jupyter Notebook. -The ```%run``` magic command allows you to run a Python script from within a Notebook. +The `%run` magic command allows you to run a Python script from within a Notebook. This is a convenient way to run scripts that you are working on in the same directory as your Notebook and present the outputs within the Notebook. @@ -188,7 +188,7 @@ This is a convenient way to run scripts that you are working on in the same dire ### Using the terminal -However, if you are looking into just running the ```.py``` file, it is sometimes easier to use the terminal. +However, if you are looking into just running the `.py` file, it is sometimes easier to use the terminal. Open a terminal from the launcher and run the following command. @@ -239,11 +239,11 @@ You can also install extensions from the Extensions tab. ```{figure} /_static/lecture_specific/workspace/vs_code_extensions.png :figclass: auto ``` -Jupyter Notebooks (```.ipynb``` files) can be worked on in VS Code. +Jupyter Notebooks (`.ipynb` files) can be worked on in VS Code. Make sure to install the Jupyter extension from the Extensions tab before you try to open a Jupyter Notebook. -Create a new file (in the file Explorer tab) and save it with the ```.ipynb``` extension. +Create a new file (in the file Explorer tab) and save it with the `.ipynb` extension. Choose a kernel/environment to run the Notebook in by clicking on the Select Kernel button on the top right corner of the editor. @@ -302,7 +302,7 @@ This creates an ipykernel console and runs the script. ### Using the terminal -The command ```python ``` is executed on the console of your choice. +The command `python ` is executed on the console of your choice. If you are using a Windows machine, you can either use the Anaconda Prompt or the Command Prompt - but, generally not the PowerShell.