Run Ipython magic functions from your profile startup python script

This is the  setup I did for a Music21 project named “chordMe”.

On WIN XP the .ipython configuration dir is in C:Documents and SettingsAdministrator.ipython

Create a profile for your project.

Open a command line shell and type the following to create a new profile

> ipython profile create chordMe
[ProfileCreate] Generating default config file: u'C:Documents and SettingsAdministrator.ipythonprofile_chordMeipython_config.py'

Now add the following python file to:
C:Documents and SettingsAdministrator.ipythonprofile_chordMestartup

000-start.py  file content:
# 000-start.py
# usage:
#     $ ipython --profile=chordMe

import os
from IPython.core.interactiveshell import InteractiveShell 
os.chdir(r"C:/1d/PythonPjs/music21Pjs/chordMePj/chordMe")

# from http://ipython.org/ipython-doc/rel-0.13/api/generated/IPython.core.interactiveshell.html
# run_line_magic(magic_name, line)
# magic_name : str  "Name of the desired magic function, without ‘%’ prefix."
# line : str "The rest of the input line as a single string."

get_ipython().run_line_magic(u"logstart", u"-o ipython_log.py append")
from music21 import *

Running Ipython with the startup commands. 
To the command line say:
> ipython --profile=chordMe
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s