Using ipython 0.11 if I type a function definition, like
def f(s): print s
then I can use that function in that ipython session, but I don't know how to define that in the ipython_config.py file. If I just type the function definition in the file and try to use the function it it undefined.
Any idea?
Multi-line functions can be defined in
*.py
and*.ipy
files under thestartup
directory within the profile directory.(Note that
*.ipy
and*.py
files are treated differently.)The profile directory can be discovered from the command line using
You'll need to define a python file to run when ipython starts. You can do this by setting the
exec_files
list:Then my file "/tmp/mymodule.py":
And finally, using this:
More information about the ipython config-file can be found here: http://ipython.org/ipython-doc/dev/config/ipython.html
Two answers here:
First, for super simple functions like the one above, you can define them in
exec_lines
, e.g.:(you can define arbitrarily complex functions this way, but it gets annoying beyond a couple of lines)
For more complicated code, you can write a script that you would like to run at startup, and add that to the
exec_files
list:We realized this is slightly annoying, so in 0.12, there will be a startup folder in profile directories, and anything you put in there will be run automatically. This is essentially adding an extra
glob.glob('*.py')
to exec_files (which you can do yourself in 0.11, of course).