Welcome to Pineapple, a graphical interface to Python based on Jupyter/IPython. Pineapple lets you organize your code into an executable notebook format that supports code, text, mathematical expressions, inline plots, and other media.
The notebook format for writing code brings many advantages.
In [1]:
# This is Python code in this cell.
# You can evaluate a cell by pressing Shift-Return
# when your cursor is in the cell.
2+2
Out[1]:
In [2]:
# You can also do normal Python things
def f(x):
return x + 5
f(10)
Out[2]:
Notice that the value of the last expression is shows in the output part of the cell. Sometimes you don't want any values. In that case you can use a semicolon at the end.
In [3]:
f(10);
You should also notice that the definition of f is still active. Even though you might have many code cells, there is just one session with Python per notebook called a kernel.
In [4]:
f(0)
Out[4]:
To help you keep track of the current Python state, each Python cell has a number next to the In[] and Out[] sections. As you execute cells you will see the numbers increase.
| Keys | Action |
|---|---|
| ⇧ Shift + Return ⏎ | Evaluate cell and move cursor down |
| ⌘ + Return ⏎ | Evaluate cell with no cursor movement |
| ⇧ Shift + ⌘ + Return ⏎ | Evaluate all cells in order |
If a computation is taking too long, or seems to be stuck in an infinite loop, you can interrupt the computation using ⌘ + I.
Here is an example that artificially takes a few seconds to finish. Try evaluating the cell. You should see the In[] number change to the busy symbol *. If you're impatient, press ⌘ + I and see what happens.
In [5]:
from time import sleep
sleep(5)
2+2
Out[5]:
Interrupting evaluation just stops computation. It does not reset the state of the Python interpreter. You can restart the Python interpreter from a blank slate through the menu option Kernel - Restart or by pressing ⌘ + 0. Any variables you have saved or functions defined will be forgotten.
Try restarting the kernel then evaluating the function call. You should see an error because f is no longer defined.
In [1]:
f(3)
Notebooks are files saved in a special text format with the extension .ipynb. The standard menu options such as New, Open, Save, and Save As should work as you expect.
Note Pineapple autosaves changes to files as you work. If you want to keep an original copy of your notebook, after opening your document immediately do Save As with a new name so your original version is not changed.
New files are named Untitled.ipynb by default and saved in your Documents directory.
You can double-click .ipynb files from Finder to open them in Pineapple.
Do not open the same file multiple times in different Pineapple windows; changes in the different windows will conflict and you may lose work.
Notebooks can be exported using Pineapple into the following formats.
Python
Output is a .py Python script. Code cells become Python code in the script, output and text cells become comments in the code.
HTML
This creates a single .html file that can be opened in a web browser
to view the notebook. Note that notebooks opened from the file are not
interactive.
Markdown
This creates either a single .md Markdown text file, or a .zip archive
containing the Markdown file together with other resources needed to display
the page (e.g. images in output cells). In the Markdown text, input code
blocks are indicated using explicit backticks, output code is indicated
using indentation.