Skip to content

Commit

Permalink
mmcky edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcky committed Dec 12, 2023
1 parent 95de21e commit 3337270
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
18 changes: 14 additions & 4 deletions lectures/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,30 +384,39 @@ 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/).

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).
<!-- IDEA: This could be turned into a margin note once supported by quantecon-book-theme -->
```{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).

<!-- IDEA: add a red square around the area of interest in the image -->
```{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

Expand All @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions lectures/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ kernelspec:

# Writing Longer Programs


```{contents} Contents
:depth: 2
```
Expand All @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -302,7 +302,7 @@ This creates an ipykernel console and runs the script.

### Using the terminal

The command ```python <path to file.py>``` is executed on the console of your choice.
The command `python <path to file.py>` 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.

Expand Down

0 comments on commit 3337270

Please sign in to comment.