None Notebook

This notebook contains material from nbpages by Jeffrey Kantor (jeff at nd.edu). The text is released under the CC-BY-NC-ND-4.0 license. The code is released under the MIT license.

< 1.3 External Files | Contents | Tag Index | 2.0 Usage >

Open in Colab

Download

1.4 Coding Style

1.4.1 Design for portability

Notebooks are intended as durable and robust means of communicating with a diverse audience. To this end, special effort attemtion must be given to making it possible to run the notebooks on multiple platforms.

1.4.2 Installations and imports

It is good practice to include all necessary installations and imports in the first executable cell of a notebook, and may be included in a special section entitled Installations and imports.

To the extent possible, the installation and import cells should be written to run cross-platform without raising exceptions. Code should be written assumming the standard Python libraries, including Matplotlib, Numpy, Pandas, and Scipy, are present. Any needed installations should included in the first code cell of the notebook and written for cross-platform use. For example, the following code installs glpk for Google Colaboratory.

import sys
if 'google.colab' in sys.modules:
    !pip install pyomo
    !pin install glpk

A try/except may be used to avoid repeated installation attempts on a user laptop:

try:
    import glpk
except:
    !pip install glpk
    import glpk

< 1.3 External Files | Contents | Tag Index | 2.0 Usage >

Open in Colab

Download