Pineapple - The Basics

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.

Why a notebook?

The notebook format for writing code brings many advantages.

  • Mix code and explanation of what you are doing
  • See your code with syntax highlighting
  • Evaluate specific parts of code as many times as needed without restarting
  • Graphical display of results
  • Code and results are organized together

Cells

A cell in Pineapple is a single block in the notebook. Cells can be different types:

  • Code (Python)
  • Text (Markdown)

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]:
4

In [2]:
# You can also do normal Python things
def f(x):
    return x + 5
f(10)


Out[2]:
15

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]:
5

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.

Evaluating Cells

Keys Action
Shift + Return Evaluate cell and move cursor down
+ Return Evaluate cell with no cursor movement
Shift + + Return Evaluate all cells in order

Interrupting

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]:
4

Restarting

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)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-1d80298e1adf> in <module>()
----> 1 f(3)

NameError: name 'f' is not defined

File Operations

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.

Export

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.