Skip to main content

Imports A.ipynb into B.ipynb

Project description

Motivation

Suppose you want to import the contents of A.ipynb into B.ipynb.

Installation

pip install import-ipynb

How to use

Place both ipynb files in the same directory. Then, in the B.ipynb:

import import_ipynb
import A

Congratulations! You can now run any functions defined in A.ipynb, from B.ipynb!

How it works

The code within import_ipynb.py defines a “notebook loader” that allows you to ‘import’ other ipynb files into your current ipynb file. This entails:

  1. load the notebook document into memory

  2. create an empty Module

  3. execute every cell in the Module namespace

Note that since every cell in the A.ipynb is executed when you import the the file, A.ipynb should only contain classes and function definitions (otherwise you’ll end up loading all variables and data into memory).

Credit

The code within imoprt_ipynb.py comes from http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Importing%20Notebooks.html. Riley F. Edmunds (@rileyedmunds) written instructions on how to use it and Lev Maximov (@axil) packaged it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

import-ipynb-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file import-ipynb-0.1.2.tar.gz.

File metadata

File hashes

Hashes for import-ipynb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a9bfd8323dd30a88b1797cb4a9befaf2149cf58a1e6467986862f26e26820a8e
MD5 45a9e8fcc66e62339e335326f3894fdb
BLAKE2b-256 646f8ad43960c3ff6d3f44415bfa6dd43237307971d94e99d8c5b7f8f793a2ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page