Lecture 7

Notebooks

MCS 275 Spring 2023
Emily Dumas

Lecture 7: Notebooks

Reminders and announcements:

  • Project 1 deadline 6pm central on Fri Feb 10.
  • Project 1 autograder opens no later than Mon Feb 6.

Project 1

  • Major focus is reading existing code.
  • Uses object-oriented programming.
  • You must add a few subclasses of an existing class.

Project 1 files

shuttle.py Edit and submit. Add subclasses as requested.
fixtures.py Read.
simulation.py Read. Use/modify for testing.
tui.py Module used by simulation.py. Don't need to read.

Project 1

Now, a demo of a solution to the project in the REPL and using simulation.py.

Python interfaces

  • REPL — One command at a time. Result is printed.
  • Script mode — Runs an entire file. Nothing printed unless explicitly requested (e.g. print(...)).

Python interfaces

  • REPL — One command at a time. Result is printed.
  • Notebook — Make groups of commands (cells) to run when ready. Last result in a cell is printed.
  • Script mode — Runs an entire file. Nothing printed unless explicitly requested (e.g. print(...)).

What notebooks look like

MCS 275 uses notebooks for homework, worksheets, and project descriptions, so you've seen these before. But you usually see a version converted to HTML.

What notebooks look like

MCS 275 uses notebooks for homework, worksheets, and project descriptions, so you've seen these before. But you usually see a version converted to HTML.

What notebooks look like

MCS 275 uses notebooks for homework, worksheets, and project descriptions, so you've seen these before. But you usually see a version converted to HTML.

How to use notebooks

Several options:
  • Google Colab — Web tool to create, edit, run notebooks. Need a Google account. Can save or download notebooks.
  • Other online provider, e.g. Kaggle, CoCalc
  • Jupyter — Software you install locally to create, edit, run notebooks. Browser shows the UI. Previously called IPython.
  • VS Code — Has an extension for handling notebook files.

Jupyter install instructions

Most users can install Jupyter using pip:

python3 -m pip install notebook

Then run the interface with:

python3 -m notebook

Of course, you need to replace python3 with your interpreter name.

Using Colab / Jupyter

A few of the many keyboard shortcuts:

  • shift-enter — run the current cell
  • escape — switch from cell editing to navigation
  • a — in nav mode, add a new cell ABOVE this one
  • b — in nav mode, add a new cell BELOW this one
  • dd — in Jupyter, in nav mode, delete current cell (colab has a delete button, and a different shortcut)
  • m — in Jupyter, in nav mode, make current cell a Markdown (text) cell

Jupyter pitfalls

The notebook interface is stateful: Behavior depends on the cells that have been evaluated so far.

If you open a previously saved notebook file, you may see old output. But you need to run all of the cells again if you want to use those values in the current session.

Cell execution order matters: Best to make a notebook that is meant to run top to bottom.

Markdown

Text cells (Colab) or markdown cells (Jupyter) contain formatted text. When editing, formatting is specified with a language called Markdown.

# Heading level 1
## Heading level 2
### Heading level 3

* Bullet list item
* Another bullet list item

1. Numbered list item
1. Another numbered list item

Links: [text to display](https://example.com)
    

References

  • Google Colab offers notebook creation, editing, execution (can use netid@uic.edu google account).
  • Some other online services allowing free use of Python notebooks: Kaggle, CoCalc
  • A Markdown guide from GitHub.

Revision history

  • 2022-01-26 Last year's lecture on this topic finalized
  • 2023-01-30 Updated version for spring 2023