-
Notifications
You must be signed in to change notification settings - Fork 0
IPython: startup script
cmoeckel91 edited this page Jul 12, 2018
·
1 revision
The IPython startup script helps in setting up commonly used modules and set up the working flow.
The startup script can be found in your home directory, inside your Profile folder.
cd ~/.Ipython/<profile_name>/startup/startup_script.py
# Import general modules
import os
import numpy as np
import matplotlib.pyplot as plt
# Change working directory to CURIE
os.chdir('/Users/chris/Documents/Research/ Toolbox')
# Allow for reload of modules
try:
reload # Python 2.7
except NameError:
try:
from importlib import reload # Python 3.4+
except ImportError:
from imp import reload # Python 3.0 - 3.3
# Ipython specific
from IPython import get_ipython
from IPython.core.magic import ( register_line_magic)
ipython = get_ipython()
ipython.magic("pylab")
ipython.magic("load_ext autoreload")
ipython.magic("autoreload 2")
ipython.magic("load_ext line_profiler")
# ex: %lprun -f function function(awdwad)
@register_line_magic('past')
@register_line_magic('pase')
@register_line_magic('pate')
@register_line_magic('psat')
@register_line_magic('psate')
@register_line_magic('pasta')
def paste_copies(line):
ipython.magics_manager.magics['line']['paste'] ()
del paste_copies
For the line profiler, you need to install it first.
conda install line_profiler
Here is how to use it:
%lprun -f function function(inputs)