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

How to use

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

import import_ipynb
import A

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

How it works

The code within import_nb.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.1.tar.gz (4.0 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for import-ipynb-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69999d134bc1de70e5bdd426fcfc325c8edc79f4c9695c5f6aa7f64f229ad7bb
MD5 e2489c37b649f860f879196685687b7e
BLAKE2b-256 6131ac4a668ab5cb06452f71f5caa923444021ecbc7d90139e0d56acf0efb5b8

See more details on using hashes here.

Supported by

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