Build IPython Laptops with Cells Already Filled

When I create a new IPython laptop, it opens a blank notebook. I would like all my laptops to open with several cells that were already filled with the material that I always use. For example, the first cell will have some magic commands

%load_ext autoreload
%autoreload 2
%matplotlib inline

The second cell may contain some standard imported

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib.collections import PatchCollection
from netCDF4 import Dataset
from tabulate import tabulate

Can I tell IPython somewhere how to create new file templates so that this can be done?

+4
source share
1 answer

You can configure the configuration file for ipython as described here . For example run:

ipython profile create

ipython (, ${HOME}/.ipython/profile_default/ipython_config.py) ( ). , , :

c = get_config()

c.InteractiveShellApp.exec_lines = [
    '%load_ext autoreload',
    '%autoreloud 2',
    '%matplotlib inline',
    'import numpy as np',
    'import matplotlib as mpl',
    'from matplotlib import pyplot as plt',
    'from matplotlib.collections import PatchCollection',
    'from netCDF4 import Dataset',
    'from tabulate import tabulate'
]

ipython .

+1

Source: https://habr.com/ru/post/1620762/


All Articles